[Toybox] [PATCH] New toy - rm

Rob Landley rob at landley.net
Wed Mar 14 20:12:52 PDT 2012


On 03/12/2012 08:34 AM, Georgi Chorbadzhiyski wrote:
> I have used fts functions. They are implemented in glibc, uclibc, bionic and BSDs.
> Unfortunately they are not implemented in musl. The fts usage is very simple and
> probably can be replaced by local traversing function which traverses the files
> and then directories in reverse order.

Hmmm... interesting.

I've now got three different traversal functions in the tree, the
dirtree stuff based on readdir(), the ls stuff based on scandir, and
this.  (Plus you've got a pending patch in here redoing chunks of
dirtree...)

I need to work out, at a design level, what the right thing is, and
change everything to use it.

The fts stuff is interesting, especially since it's already written so
we get most of it for free.  But googling for it turns up a lot of
accidental memory exhaustion issues from failure to scale to large
directories.  Accidentally creating a large directory and then being
unable to rm -rf the sucker is a bad thing.

I think those can be avoided by using fts_read() instead of
fts_children(), but I'm not really sure.  The lifetime rules for these
objects are implicit, not clearly stated.

Another issue is that it always creates an absolute path from root.  If
you request a whole tree (such as for tar), that's a potentially very
large memory requirement. (And fts_cycle is kinda creepy.)

Still, "this is already in libc" is a pretty powerful argument...

Lemme get back to this one.

Rob

 1331781172.0


More information about the Toybox mailing list