Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Oct 1996 05:54:09 -0700 (PDT)
From:      Peter Wemm <peter>
To:        CVS-committers, cvs-all, cvs-usrbin
Subject:   cvs commit:  src/usr.bin/find extern.h find.1 find.h function.c option.c
Message-ID:  <199610041254.FAA16501@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
peter       96/10/04 05:54:09

  Modified:    usr.bin/find  extern.h find.1 find.h function.c option.c
  Log:
  Implement a -delete option to find.  The code is extremely paranoid and
  goes to a fair degree of trouble to enable something like this to
  be safe:  cd /tmp && find . -mtime +7 -delete
  
  It removes both files and directories.  It does not attempt to remove
  immutable files (an earlier version I showed to a few people did a chflags
  and tried to blow away even immutable files.  Too risky..)
  
  It is thought to be safe because it forces the fts(3) driven descent to
  only do "minimal risk" stuff.  specifically, -follow is disabled, it does
  checking to see that it chdir'ed to the directory it thought it was
  going to, it will *not* pass a pathname with a '/' character in it to
  unlink(), so it should be totally immune to symlink tree races.  If it runs
  into something "fishy", it bails out rather than blunder ahead.. It's better
  to do that if somebody is trying to compromise security rather than risk
  giving them an opportunity.  Since the unlink()/rmdir() is being called
  from within the current working directory during the tree descent, there
  are no fork/exec overheads or races.
  
  As a side effect of this paranoia, you cannot do a
  "find /somewhere/dir -delete", as the last argument to rmdir() is
  "/somewhere/dir", and the checking won't allow it.  Besides, one would use
  rm -rf for that case anyway. :-)
  
  Reviewed by: pst (some time ago, but I've removed the immutable file
  deletion code that he complained about since he last saw it)
  
  Revision  Changes    Path
  1.3       +1 -0      src/usr.bin/find/extern.h
  1.4       +14 -1     src/usr.bin/find/find.1
  1.3       +1 -1      src/usr.bin/find/find.h
  1.8       +53 -0     src/usr.bin/find/function.c
  1.3       +1 -0      src/usr.bin/find/option.c



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610041254.FAA16501>