[Qt-interest] Symbolic link real value?
Pau Garcia i Quiles
pgquiles at elpauer.org
Tue Jul 28 13:57:44 CEST 2009
On Tue, Jul 28, 2009 at 1:52 PM, Lukas Lipavsky<llipavsky at suse.cz> wrote:
> On 28.07. 13:47, Pau Garcia i Quiles wrote:
>> On Tue, Jul 28, 2009 at 1:40 PM, Lukas Lipavsky<llipavsky at suse.cz> wrote:
>> > Hi,
>> >
>> > is there any way to get the path symlink (in linux) is pointing to? But
>> > I need the real value - e.g. '../../dir/file'
>> >
>> > All I found so far was QFileInfo::symLinkTarget() but it returns
>> > *absolute* path, which is useless for me.
>> >
>> > Is there any way to get this information from the Qt library (better
>> > than calling ls)?
>>
>> Use QDir::relativeFilePath with the current directory (QDir::current() )
>>
>> http://doc.trolltech.com/4.5/qdir.html#relativeFilePath
>> http://doc.trolltech.com/4.5/qdir.html#current
>
> thanks,
>
> but unfortunatelly, this won't help me either. To make it more clean, I
> am writing a synchronization app that would synchronize the content of
> two directories (on different hosts). For this I need to be able to
> synchronize the symbolic link to the same state as it is, so if it's
> absolute, keep it absolute, if it's relative, keep it relative...
>
> Is there any way to do this?
Match the result of QFile::symLinkTarget() against "..":
- It it contains "..", it's a relative symlink and you should then use
QDir::relativeFilePath() and Qdir::current() to get in the destination
machine the same path as in the origin machine.
- It it does not contain "..", it's an absolute symlink and the output
of QFile::symLinkTarget() is what you want.
--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
More information about the Qt-interest-old
mailing list