diff --git a/cleandir/cleandir b/cleandir/cleandir index 8bf4b7f..7c89160 100755 --- a/cleandir/cleandir +++ b/cleandir/cleandir @@ -23,12 +23,18 @@ sub cleandir { return; } my $std = lstat("."); + my $fs = $std->dev; + for my $i (readdir(DIR)) { if ($i eq "." || $i eq "..") {next} if ($verbose > 2) { print STDERR "$0:", " " x $level, " checking $dir/$i\n"; } my $st = lstat("$i"); + + # Skip anything on a different filesystem + next if ($st->dev != $fs); + if ($verbose > 3) { print STDERR "$0:", " " x $level, " mtime=", $st->mtime, " atime=", $st->atime, "\n"; } @@ -56,6 +62,7 @@ sub cleandir { " to ", $std1->dev, "/", $std1->ino, "\n"; + return ++$notremoved; } if ($remaining == 0 && $st->mtime < $since) { if ($verbose > 0) { @@ -113,7 +120,14 @@ sub main { main(); # $Log: cleandir,v $ -# Revision 1.4 2000-11-20 21:10:08 hjp +# Revision 1.5 2002-02-25 23:23:10 hjp +# Applied patch from "Chris L. Mason" to prevent +# filesystem traversal. +# +# Return immediately if we cannot chdir back to the directory we came +# from. +# +# Revision 1.4 2000/11/20 21:10:08 hjp # Checks introduced in last version prevented deletion of unused subdirs. # Fixed. #