Critical bug fix: Empty directories were removed even with -n.

Minor cleanup: Message "removing ..." is now the same with and without -n.
This commit is contained in:
hjp 2004-11-02 09:01:12 +00:00
parent fd3d3341ca
commit e8c3f76218
1 changed files with 13 additions and 10 deletions

View File

@ -130,24 +130,23 @@ sub cleandir {
if ($verbose > 0) { if ($verbose > 0) {
print STDERR "$0:", " " x $level, "rmdir $i\n"; print STDERR "$0:", " " x $level, "rmdir $i\n";
} }
if (rmdir("$i")) {next} unless ($nop) {
print STDERR "$0:", " " x $level, "rmdir $i failed: $!\n"; if (rmdir("$i")) {next}
print STDERR "$0:", " " x $level, "rmdir $i failed: $!\n";
}
} }
} else { } else {
print STDERR "$0:", " " x $level, " chdir $dir/$i failed: $!\n"; print STDERR "$0:", " " x $level, " chdir $dir/$i failed: $!\n";
} }
} elsif ($st->mtime < $since && ($st->atime < $since || $mtime_only)) { } elsif ($st->mtime < $since && ($st->atime < $since || $mtime_only)) {
if ($nop) { if ($verbose > 0) {
print "would remove $dir/$i\n"; print STDERR "$0:", " " x $level, " removing $dir/$i\n";
} else { }
if ($verbose > 0) { unless ($nop) {
print STDERR "$0:", " " x $level, " removing $dir/$i\n";
}
if (unlink("$i")) {next} if (unlink("$i")) {next}
print STDERR "$0:", " " x $level, " removing $dir/$i failed: $!\n"; print STDERR "$0:", " " x $level, " removing $dir/$i failed: $!\n";
} }
} }
$notremoved++; $notremoved++;
} }
@ -186,7 +185,11 @@ sub main {
main(); main();
# $Log: cleandir.pl,v $ # $Log: cleandir.pl,v $
# Revision 1.6 2003-05-16 14:44:58 hjp # Revision 1.7 2004-11-02 09:01:12 hjp
# Critical bug fix: Empty directories were removed even with -n.
# Minor cleanup: Message "removing ..." is now the same with and without -n.
#
# Revision 1.6 2003/05/16 14:44:58 hjp
# Added -m option to synopsis. # Added -m option to synopsis.
# #
# Revision 1.5 2003/05/16 13:38:25 hjp # Revision 1.5 2003/05/16 13:38:25 hjp