[Qt-interest] Symbolic link real value?
Pau Garcia i Quiles
pgquiles at elpauer.org
Tue Jul 28 15:14:14 CEST 2009
On Tue, Jul 28, 2009 at 2:02 PM, Lukas Lipavsky<llipavsky at suse.cz> wrote:
> On 28.07. 13:57, Pau Garcia i Quiles wrote:
>> 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.
>
> No, it does not:
> 1. relative path does not need to contain '..'
You are right. Check for "./", ".\", etc too.
> 2. even if it worked, symLinkTarget() never returns path with '..',
> because it always return absolute path. If it would return relative
> path, that would be exactly what I need.
You are confusing absolute path with canonical path.From
http://doc.trolltech.com/4.5/qfileinfo.html#absoluteFilePath
QString QFileInfo::absoluteFilePath () const
[...]
This function returns the same as filePath(), unless isRelative() is
true. In contrast to canonicalFilePath(), symbolic links or redundant
"." or ".." elements are not necessarily removed
--
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