[Toybox] Poking at dirtree.
Georgi Chorbadzhiyski
gf at unixsol.org
Tue Mar 27 06:37:39 PDT 2012
Around 03/26/2012 06:02 AM, Rob Landley scribbled:
> I spent a longish time this weekend redoing the lib/dirtree.c stuff, and
> now I need to test it a _lot) more and redo cp.c to use it properly. (I
> don't want to check it in while it still breaks stuff, but if you're
> curious I attached the "hey, it compiled!" version.)
>
> The point of this exercise is to unify the fts, scandir(), and readdir()
> stuff into a single set of code everything can use.
>
> I was tempted to just use the fts stuff since it's closest to what I
> want and already there in the library, but if you google for it they
> have problems scaling to large directories. One problem is they put an
> absolute path from root in every node, which can add up quickly if you
> have large directories with deep paths. (Instead I made a function that
> creates the directory path when you ask it to, and then you can feed
> that to realpath() yourself if you need it cannonicalized.)
>
> I'm going the other way and using the openat() stuff, which is in posix
> 2008 now. This elimiates the old PATH_MAX dependency, and weans dirtree
> off of toybuf, which was a layering violation anyway: commands should
> always have toybuf free for their own use, meaning the library should
> NOT use it beyond a command's back.
>
> I know the fts stuff is calling directory callbacks when both entering
> and leaving a directory, which might be a good idea, but I purposely
> _didn't_ implement that yet because it's infrastructure in search of a
> user. When I have an actual use case for that, it's easy enough to add
> in later.
>
> Sorry I've been distracted recently: I've been doing package upgrades in
> aboriginal linux to get a release out there. (I'm mostly caught on on
> the new kernel, but still need to upgrade uClibc and fix the regressions
> that's bound to cause...)
What is mostly needed is that the dirtree stuff executes callbacks from the
bottom of the tree up. For example if we have "a/b/c/{d,e}/file{1,2,3}.txt" and dirtree_recurse
is called on "a" for cp/rm/rmdir/chmod/chown/etc it'll need to get
a/b/c/d/file1.txt
a/b/c/d/file2.txt
a/b/c/d/file3.txt
a/b/c/d
a/b/c/e/fileX.txt
a/b/c/e
a/b/c
a/b
a
That is what we get with fts the way I used it in rm. Is that possible with the
new infrastructure?
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
--
Georgi Chorbadzhiyski
http://georgi.unixsol.org/
1332855459.0
More information about the Toybox
mailing list