[Toybox] dirtree help

Georgi Chorbadzhiyski gf at unixsol.org
Tue Apr 24 03:21:47 PDT 2012


I'm porting chXXX toys to the new dirtree code but I'm running into a problem.
Apply the attached patch and see the difference in outputs from coreutils
chgrp and toybox chgrp toy.

gf at gf:~/git/toybox$ chgrp -R root test
chgrp: changing group of `test/rm.c': Operation not permitted
chgrp: changing group of `test/a/b/Makefile': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d2/e/blah.c': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d2/e/Makefile': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d2/e/blah': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d2/e': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d2': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d1/blah.c': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d1/Makefile': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d1/blah': Operation not permitted
chgrp: changing group of `test/a/b/c/d/d1': Operation not permitted
chgrp: changing group of `test/a/b/c/d': Operation not permitted
chgrp: changing group of `test/a/b/c': Operation not permitted
chgrp: changing group of `test/a/b/rm.c': Operation not permitted
chgrp: changing group of `test/a/b/rm.1': Operation not permitted
chgrp: changing group of `test/a/b/rm': Operation not permitted
chgrp: changing group of `test/a/b': Operation not permitted
chgrp: changing group of `test/a/c/d/file.txt': Operation not permitted
chgrp: changing group of `test/a/c/d': Operation not permitted
chgrp: changing group of `test/a/c': Operation not permitted
chgrp: changing group of `test/a': Operation not permitted
chgrp: changing group of `test/rm': Operation not permitted
chgrp: changing group of `test': Operation not permitted

gf at gf:~/git/toybox$ ./toybox chgrp -R root test
chgrp: changing group of 'test' to 'root': Operation not permitted
chgrp: changing group of 'test' to 'root': Operation not permitted
chgrp: changing group of 'test/rm.c' to 'root': Operation not permitted
chgrp: changing group of 'test/a' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/Makefile' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2/e' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2/e/blah.c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2/e/Makefile' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2/e/blah' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2/e' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d2' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d1' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d1/blah.c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d1/Makefile' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d1/blah' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d/d1' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c/d' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/rm.c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/rm.1' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b/rm' to 'root': Operation not permitted
chgrp: changing group of 'test/a/b' to 'root': Operation not permitted
chgrp: changing group of 'test/a/c' to 'root': Operation not permitted
chgrp: changing group of 'test/a/c/d' to 'root': Operation not permitted
chgrp: changing group of 'test/a/c/d/file.txt' to 'root': Operation not permitted
chgrp: changing group of 'test/a/c/d' to 'root': Operation not permitted
chgrp: changing group of 'test/a/c' to 'root': Operation not permitted
chgrp: changing group of 'test/a' to 'root': Operation not permitted
chgrp: changing group of 'test/rm' to 'root': Operation not permitted
chgrp: changing group of 'test' to 'root': Operation not permitted

I see DIRTREE_COMEAGAIN and DIRTREE_NOSAVE flags but I have no idea how to use
them to achieve the effect that coreutils directory recursion is having.

Help, please.

-- 
Georgi Chorbadzhiyski
http://georgi.unixsol.org/
-------------- next part --------------
diff --git a/toys/chgrp.c b/toys/chgrp.c
index 2ad8a02..b35e95d 100644
--- a/toys/chgrp.c
+++ b/toys/chgrp.c
@@ -48,23 +48,18 @@ static int do_chgrp(const char *path) {
 	return ret;
 }
 
-// Copied from toys/cp.c:cp_node()
-int chgrp_node(char *path, struct dirtree *node)
+int chgrp_node(struct dirtree *node)
 {
-	char *s = path + strlen(path);
-	struct dirtree *n = node;
-
-	for ( ; ; n = n->parent) {
-		while (s!=path) {
-			if (*(--s) == '/') break;
-		}
-		if (!n) break;
+	int is_dotdot = dirtree_isdotdot(node);
+	if (!is_dotdot) {
+		int len = 0;
+		char *path = dirtree_path(node, &len);
+		do_chgrp(path);
+		free(path);
+		return 0;
+	} else {
+		return is_dotdot;
 	}
-	if (s != path) s++;
-
-	do_chgrp(s);
-
-	return 0;
 }
 
 void chgrp_main(void)
@@ -94,7 +89,7 @@ void chgrp_main(void)
 			if (S_ISDIR(sb.st_mode)) {
 				strncpy(toybuf, *s, sizeof(toybuf) - 1);
 				toybuf[sizeof(toybuf) - 1] = 0;
-				dirtree_read(toybuf, NULL, chgrp_node);
+				dirtree_read(toybuf, chgrp_node);
 			}
 		}
 	} else {


More information about the Toybox mailing list