[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: #19519: tmpreaper: Will not remove dirs



karlheg@bittersweet.inetarena.com (Karl M. Hegbloom) writes:

[ I didn't send this to the bug system.  Is that what you meant? ]

>  There is some difficulty in programming this `mtime-mt-dir' option.
>  The problem is that it must first recurse down any subdirectories to
>  look for files to remove there, prior to attempting to remove the
>  directory itself.  If there's any files there that get removed, the
>  mtime of that directory will be changed.

Assuming that you don't have to worry about new files inserted into
the tree while tmpreaper is running (do you?), then it's probably
easiest to just do this operation in two passes.  (This is off the top
of my head, so I'm nearly certain there's a better approach):

  1) Scan the tree collecting separately a list of directory timestamps
     and a list of timestamps for everything else.
  2) Make sure the dir list is sorted such that subdirs always appear
     after parent dirs.
  3) Scan the list from top to bottom, deleting any dirs with old
     enough timestamps (you'll get errors for subdirs of deleted dirs,
     but ignore those...)
  4) Now you know that you've killed all the dirs and many of the
     files that it's OK to delete, so scan the list of non-dirs and
     delete any with old enough timestamps, ignoring existence errors.

In step 3, you could go bottom to top to avoid the errors, but this
would be much slower, and you could just avoid the errors with an
existence test before each delete.

This algorithm would be easy to write in perl.  I might be able to get
you code if you like.  I've got something similar already, but I
wasn't really worried about security issues when I wrote it, so it
might not be appropriate.  It *is* really careful about file names,
using null as a file name terminator while generating lists, so you
don't get fooled by other characters in filenames.

-- 
Rob Browning <rlb@cs.utexas.edu>
PGP fingerprint = E8 0E 0D 04 F5 21 A0 94  53 2B 97 F5 D6 4E 39 30


--
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: