[Toybox] I live!
Rob Landley
rob at landley.net
Sat Mar 31 11:59:39 PDT 2012
Ok, weekend. Time to catch up.
I need to test the dirtree stuff, and the first big user of the dirtree
stuff is (theoretically) ls, so I'm digging into that. (I could use the
cp I wrote way back when, but that writes output and can make a mess, ls
is read-only.)
In practice, the logic of ls -R isn't really the same as "tar". It
doesn't descend into a directory at discovery time, instead it defers
subdirectory processing to the end of each directory.
If I go "ls file1 dir1 file2 dir2 file3" it displays file1, file2, and
file3, then displays dir1's contents, then dir2's contents. It's
putting them on a deferred list, and appending to that list.
Hmmm, not quite. If I do "ls -lR configure LICENSE scripts toys.h toys
lib" the contents of scripts/test winds up between "scripts" and "toys",
not at the end. So -R is in fact recursing, but within a directory all
files are handled before all directories.
And it does file readahead for the entire directory contents. Even with
-f or -U strace says the underlying syscall is getdents() with buffer
size 1000. (Well, 998 for some reason. . and .. I guess?)
The -f seems to disable ls's internal need to examine everything before
producting output, -U does not. (Part of this is that -f disables -l
even if both are supplied, -U still does the padding so it did the
readahead.)
The readahead is for display purposes: it figures out the maximum size
needed for each field and pads them with spaces. The string fields
(user and group name) are left justified, the number fields (hardlink
count and bytes) are right justified.
Right, how does that match up with what dirtree() is doing? Looks like I
need the callback to always return "do not recurse", and then manually
call the recursion function later on...
Ooh. I get it. The callback should return a bitfield telling the
caller what to do: recurse into children, call me back again after
recursing into children, don't add this entry to the tree...
/me wanders away to code for a bit...
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.
More information about the Toybox
mailing list