[Toybox] What does the du.c patch do?
Rob Landley
rob at landley.net
Sat Nov 29 16:33:52 PST 2014
Going through Ashwini's patch stack from last month. (Sorry for the delay,
but I think I applied all the trivial ones in earlier passes.)
What does the du.c patch do?
$ mkdir sub
$ ln -s . sub/here
$ ln -s loop sub/loop
$ ./toybox du sub
4 sub
There's also a hardlink filter (disabled via -l)...
I'm tempted to add the following to lib/dirtree.c
+// Have we already seen this node?
+int dirtree_seen(struct dirtree *try, struct stat *st)
+{
+ while (try) {
+ if (try->st.st_ino==st->st_ino && try->st.st_dev==st->st_dev) return 1;
+ try = try->parent;
+ }
+
+ return 0;
+}
+
But the existing user I can think of that's already doing this is in cp.c:
// Detect recursive copies via repeated top node (cp -R .. .) or
// identical source/target (fun with hardlinks).
if ((TT.top.st_dev == try->st.st_dev && TT.top.st_ino == try->st.st_ino
&& (catch = TT.destname))
|| (!fstatat(cfd, catch, &cst, 0) && cst.st_dev == try->st.st_dev
&& cst.st_ino == try->st.st_ino))
{
error_msg("'%s' is '%s'", catch, err = dirtree_path(try, 0));
free(err);
return 0;
}
Which seems to work?
Anyway, could you give me a testcase where the du.c patch you submitted makes a
difference?
Rob
More information about the Toybox
mailing list