[Toybox] Poking at dirtree.

Rob Landley rob at landley.net
Sat Mar 31 12:42:17 PDT 2012


On 03/27/2012 08:37 AM, Georgi Chorbadzhiyski wrote:
> The other thing with fts is the ability to request FTS_LOGICAL or FTS_PHYSICAL
> (possible FTS_XDEV will be neede for find -xdev). The difference is the LOGICAL
> follows symlinks and PHISYCAL do not. These options allow us to implement -H/-L
> options of chown - http://pubs.opengroup.org/onlinepubs/009695399/utilities/chown.html

I'm adding a bunch of DIRTREE_BLAH flags that callbacks can or together
and return, and one of them is DIRTREE_SYMFOLLOW.

I'm not sure if this means it should recursively follow symlinks to
directories, or if it should use stat() instead of lstat() and always
record what the symlink points to rather than the fact it's a symlink.

I think the second is slightly conceptually clearer, but I'm open to
second opinions here. (For chown I don't think it matters.  For cp I
think -L means stat instead of lstat, but I haven't tested it yet
because "cp" and "rm" are both things I prefer to test under qemu rather
than horking my host system. :)

(Did you know that cp -L on a symlink loop eventually stops with EMLINK
when you're only about 20 deep?  Good to know.  Except I _think_ that's
an implementation artifact of the way busybox's cp handles things,
rather than a limit on how deep a directory tree you can create, it
makes a source symlink/symlink/symlink path that eventually maxes out.
If I'm using openat() I don't think it'll stop, and I may fill up all
the inodes in the target system, which then gets fun to rm -rf...)

Yes, I want to make these sort of corner cases work. -L is dangerous by
design. I may need more active symlink loop detection, hardlink
detection basically means you check both the device and inode numbers in
statbuf for equality. Yeah, checking all the parent nodes of each
directory is nlog(n) with the depth of the tree: I'm ok with that.
Possibly for standards compliance I need some sort of --crazy flag to
say "yes, I really do want to copy a symlink loop and fill up all inodes
in the system"...)

Rob
-- 
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation.  Pick one.

 1333222937.0


More information about the Toybox mailing list