Bug 91096 - Add option so that tmpwatch can handle removing empty directories
Summary: Add option so that tmpwatch can handle removing empty directories
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: tmpwatch
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Miloslav Trmač
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-05-17 22:09 UTC by Craig Lawson
Modified: 2007-11-30 22:10 UTC (History)
2 users (show)

Fixed In Version: 2.9.4-1
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-06-20 13:52:20 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Craig Lawson 2003-05-17 22:09:35 UTC
Description of problem:
  Tmpwatch does not delete empty directories. I suspect it is because something
updates each directory's access time. A fix would be to automatically delete
empty directories, no matter when they were accessed last (provided no user had
the directory open).
  Previous bug reports have claimed that tmpwatch itself was changing each
directory's access time, thus hosing itself, but RedHat QA has been unable to
replicate the bug. Could be that slocate is changing access time, and this is
why tmpwatch deletes old files but not empty directories.

Version-Release number of selected component (if applicable):
tmpwatch-2.8.4-5

How reproducible:
100%

Steps to Reproduce:
1. Create an empty directory.
2. Run slocate with -U or -u option.
3. Check the directory's access time.
4. Run tmpwatch to check the directory.

Actual results:
tmpwatch will not delete the empty directory.

Expected results:
I did not really expect it to because the access time was recent. However, I
wish for a new option so that tmpwatch will delete empty directories no matter
when they were last accessed.

Additional info:

Also see:
  Bug 3146
  Bug 14930

For the impatient, here is a script that will remove all empty directories found
in a tree:

  for D; do
    echo "Checking: $D"
    # Locate all subdirectories, depth first, and try to rmdir.
    # rmdir will fail if the directory is not empty.
    find "$D" -depth -type d -print0 |
      xargs -0 rmdir --ignore-fail-on-non-empty
  done

Comment 1 Miloslav Trmač 2004-08-13 21:31:21 UTC
When running from a cron job (which is the expected usage model
of tmpwatch), removing all empty directories can lead to race
conditions between tmpwatch and other programs that create
a temporary directory and then attempt to store files in it.

Even "keeping the directory open" by chdir () to the directory
doesn't remove the race condition in the time between mkdir () and
chdir ().

If that race condition would trigger, it would lead to mysterious
program failures that would be virtually impossible to reproduce.

Comment 2 Matthew Miller 2005-05-16 21:52:46 UTC
Reopening as per discussion on fedora-devel-list.

As it stands, tmpwatch basically never removes directories unless given --ctime
or --mtime. However, it would often be desirable to use --mtime for directories
and --atime for regular files (as suggested in bug #14930 by Aleksey Nogin), and
there's currently not an option that allows that.

Removing directories could still be a little dangerous -- they could be being
used for simple inter-process communication, for example. However, there already
is the -d/--nodirs option to not remove directories. Therefore, one approach
would be to make --atime always use mtime for directories, and use -d in the
standard cron scripts.

That would introduce a change in behavior which might bite people, however. So,
it's probably best to keep current behavior as-is and add a new option --
something like --mtime-dirs (no idea what a good short option would be, since -d
is already taken).

Or, we could totally change the ui, and add options like this:

  --check-files=[atime,mtime,ctime]
  --check-dirs=[atime,mtime,ctime]
  --check-others=[atime,mtime,ctime]

but maybe that's getting silly.

Comment 3 Miloslav Trmač 2005-06-20 13:52:20 UTC
tmpwatch-2.9.4 has --dirmtime.
The current state (--[acm]time --dirmtime) is as complicated as the options can
get; I can see no good reason to discriminate between regular files and other
non-directories; atime for directories is used if atime is used for other files,
ctime doesn't make sense for directories because even removing a file from a
directory updates the ctime.

Thanks for proposing this alternative again.

Comment 4 Matthew Miller 2005-06-20 13:58:54 UTC
Cool. :)


Note You need to log in before you can comment on or make changes to this bug.