Bug 91096 - Add option so that tmpwatch can handle removing empty directories
Add option so that tmpwatch can handle removing empty directories
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: tmpwatch (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Miloslav Trmač
Ben Levenson
: FutureFeature
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-05-17 18:09 EDT by Craig Lawson
Modified: 2007-11-30 17:10 EST (History)
2 users (show)

See Also:
Fixed In Version: 2.9.4-1
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-06-20 09:52:20 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Craig Lawson 2003-05-17 18:09:35 EDT
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 17:31:21 EDT
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 17:52:46 EDT
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 09:52:20 EDT
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 09:58:54 EDT
Cool. :)

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