[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: readlink bugs
From:       Denis Vlasenko <vda.linux () googlemail ! com>
Date:       2006-10-22 0:32:20
Message-ID: 200610220232.20719.vda.linux () googlemail ! com
[Download RAW message or body]

> No, it's the one from coreutils
> $ dpkg -S /bin/readlink 
> coreutils: /bin/readlink
> $ dpkg -l coreutils | tail -n 1
> ii  coreutils      5.97-5         The GNU core utilities

Yours are newer.

> $ /bin/readlink -f /tmp/no_such_file;echo $?
> /tmp/no_such_file
> 0
> 
> Since several scripts use -f, i think it's worthwile to fix this case.
> Otherwise the applet is not really useable. So.. any better idea on how
> to fix this for good? There could be more applets that potentially need
> to normalize pathes (i.e. collaps them), didn't look which these may be,
> though.

Yes, there are. cp -sdR a/../contrived/dangling/symlink copy
will love to have "better realpath()"

Background: cp -sR /tree dir makes a copy with symlinks.
If some of tree files are symlinks themself, we get symlinks to symlinks.
Since cp already has -d option, we theoretically can overload it
for -s to mean "make it so that created symlinks point to final destination".
But we can't: if some of those /tree/symlinks are DANGLING,
then realpath() does not 'canonicalize' them. Returns NULL instead.

You want readlink -f nonexistent_file to work.
I think it makes sense to make readlink -f danglink_link
to also work.

Just checked. coreutils 6.3:

readlink -f /not/exist        prints /not/exist
readlink -f /dagling/link     prints /dagling/link
(at least if "link" -> "bogus". "link" -> "bogus/../foo"
 gives no output and exitcode 1)
 
Actually, coreutils has whole slew of options:
  -f, --canonicalize            canonicalize by following every symlink in
                                every component of the given name recursively;
                                all but the last component must exist
  -e, --canonicalize-existing   canonicalize by following every symlink in
                                every component of the given name recursively,
                                all components must exist
  -m, --canonicalize-missing    canonicalize by following every symlink in
                                every component of the given name recursively,
                                without requirements on components existence
  -n, --no-newline              do not output the trailing newline
  -q, --quiet,
  -s, --silent                  suppress most error messages
  -v, --verbose                 report error messages

> Thoughts?

The best would be to implement readlink -f in coreutils-compatible way.
uclibc/glibc hava to have readlink() code available. Maybe makes
sense to take a look in additional to coreutils code
(which looks bloaty).
--
vda
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic