aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/du.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-05-09 18:11:22 -0500
committerRob Landley <rob@landley.net>2015-05-09 18:11:22 -0500
commitaab9164df395a4b0878b0ad930a5ec8a806a58e9 (patch)
treeae36c520e5ebeaf616755792f67c9e09ff1bbf9f /toys/posix/du.c
parenta913d92bad6550e005a3ffac71a82586042171b5 (diff)
downloadtoybox-aab9164df395a4b0878b0ad930a5ec8a806a58e9.tar.gz
Add DIRTREE_SHUTUP to disable dirtree warnings if file vanishes out from
under traversal. Pass through full flag set in dirtree_add_node(), add dirtree_start() wrapper to provide symlink-only behavior (avoiding a lot of DIRTREE_SYMFOLLOW*!!(logic) repeated in callers).
Diffstat (limited to 'toys/posix/du.c')
-rw-r--r--toys/posix/du.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/toys/posix/du.c b/toys/posix/du.c
index 00a7f68a..0dea495c 100644
--- a/toys/posix/du.c
+++ b/toys/posix/du.c
@@ -104,7 +104,8 @@ static int seen_inode(void **list, struct stat *st)
// dirtree callback, comput/display size of node
static int do_du(struct dirtree *node)
{
- if (node->parent && !dirtree_notdotdot(node)) return 0;
+ if (!node->parent) TT.st_dev = node->st.st_dev;
+ else if (!dirtree_notdotdot(node)) return 0;
// detect swiching filesystems
if ((toys.optflags & FLAG_x) && (TT.st_dev != node->st.st_dev))
@@ -146,21 +147,12 @@ static int do_du(struct dirtree *node)
void du_main(void)
{
- char *noargs[] = {".", 0};
- struct dirtree *root;
-
- if (!toys.optc) toys.optargs = noargs;
+ char *noargs[] = {".", 0}, **args;
// Loop over command line arguments, recursing through children
- while (*toys.optargs) {
- root = dirtree_add_node(0, *toys.optargs, toys.optflags & (FLAG_H|FLAG_L));
-
- if (root) {
- TT.st_dev = root->st.st_dev;
- dirtree_handle_callback(root, do_du);
- }
- toys.optargs++;
- }
+ for (args = toys.optc ? toys.optargs : noargs; *args; args++)
+ dirtree_handle_callback(dirtree_start(*args,
+ DIRTREE_SYMFOLLOW*!!(toys.optflags & (FLAG_H|FLAG_L))), do_du);
if (toys.optflags & FLAG_c) print(TT.total*512, 0);
if (CFG_TOYBOX_FREE) seen_inode(TT.inodes, 0);