aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
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
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')
-rw-r--r--toys/posix/chgrp.c15
-rw-r--r--toys/posix/cp.c4
-rw-r--r--toys/posix/du.c20
-rw-r--r--toys/posix/find.c9
-rw-r--r--toys/posix/ls.c6
5 files changed, 20 insertions, 34 deletions
diff --git a/toys/posix/chgrp.c b/toys/posix/chgrp.c
index fb82adbd..6b95c6ad 100644
--- a/toys/posix/chgrp.c
+++ b/toys/posix/chgrp.c
@@ -49,12 +49,11 @@ static int do_chgrp(struct dirtree *node)
// Depth first search
if (!dirtree_notdotdot(node)) return 0;
if ((flags & FLAG_R) && !node->again && S_ISDIR(node->st.st_mode))
- return DIRTREE_COMEAGAIN|((flags&FLAG_L) ? DIRTREE_SYMFOLLOW : 0);
+ return DIRTREE_COMEAGAIN|(DIRTREE_SYMFOLLOW*!!(flags&FLAG_L));
fd = dirtree_parentfd(node);
ret = fchownat(fd, node->name, TT.owner, TT.group,
- (flags&(FLAG_L|FLAG_H)) || !(flags&(FLAG_h|FLAG_R))
- ? 0 : AT_SYMLINK_NOFOLLOW);
+ AT_SYMLINK_NOFOLLOW*(!(flags&(FLAG_L|FLAG_H)) && (flags&(FLAG_h|FLAG_R))));
if (ret || (flags & FLAG_v)) {
char *path = dirtree_path(node, 0);
@@ -74,7 +73,7 @@ static int do_chgrp(struct dirtree *node)
void chgrp_main(void)
{
- int ischown = toys.which->name[2] == 'o', hl = toys.optflags&(FLAG_H|FLAG_L);
+ int ischown = toys.which->name[2] == 'o';
char **s, *own;
TT.owner = TT.group = -1;
@@ -94,11 +93,9 @@ void chgrp_main(void)
if (TT.group_name && *TT.group_name)
TT.group = xgetgrnamid(TT.group_name)->gr_gid;
- for (s=toys.optargs+1; *s; s++) {
- struct dirtree *new = dirtree_add_node(0, *s, hl);
- if (new) dirtree_handle_callback(new, do_chgrp);
- else toys.exitval = 1;
- }
+ for (s=toys.optargs+1; *s; s++)
+ dirtree_handle_callback(dirtree_start(*s, toys.optflags&(FLAG_H|FLAG_L)),
+ do_chgrp);;
if (CFG_TOYBOX_FREE && ischown) free(own);
}
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index 2959f67c..df8269f3 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -340,9 +340,9 @@ void cp_main(void)
// Skip nonexistent sources
if (rc) {
- int symfollow = toys.optflags & (FLAG_H|FLAG_L);
+ int symfollow = DIRTREE_SYMFOLLOW*!!(toys.optflags & (FLAG_H|FLAG_L));
- if (errno != EXDEV || !(new = dirtree_add_node(0, src, symfollow)))
+ if (errno != EXDEV || !(new = dirtree_start(src, symfollow)))
perror_msg("bad '%s'", src);
else dirtree_handle_callback(new, TT.callback);
}
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);
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 69e370d4..73502b4a 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -531,12 +531,9 @@ void find_main(void)
do_find(0);
// Loop through paths
- for (i = 0; i < len; i++) {
- struct dirtree *new;
-
- new = dirtree_add_node(0, ss[i], toys.optflags&(FLAG_H|FLAG_L));
- if (new) dirtree_handle_callback(new, do_find);
- }
+ for (i = 0; i < len; i++)
+ dirtree_handle_callback(dirtree_start(ss[i], toys.optflags&(FLAG_H|FLAG_L)),
+ do_find);
if (CFG_TOYBOX_FREE) {
close(TT.topdir);
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index 5dd6bc50..3e5d3910 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -540,10 +540,10 @@ void ls_main(void)
// Iterate through command line arguments, collecting directories and files.
// Non-absolute paths are relative to current directory.
- TT.files = dirtree_add_node(0, 0, 0);
+ TT.files = dirtree_start(0, 0);
for (s = *toys.optargs ? toys.optargs : noargs; *s; s++) {
- dt = dirtree_add_node(0, *s, !(toys.optflags & (FLAG_l|FLAG_d|FLAG_F))
- || (toys.optflags & (FLAG_L|FLAG_H)));
+ dt = dirtree_start(*s, !(toys.optflags&(FLAG_l|FLAG_d|FLAG_F)) ||
+ (toys.optflags&(FLAG_L|FLAG_H)));
if (!dt) {
toys.exitval = 1;