|
1 | 1 | #!/usr/bin/env perl |
2 | 2 |
|
3 | 3 | use strict; |
| 4 | +use warnings; |
| 5 | + |
4 | 6 | use POSIX qw(strftime); |
5 | 7 |
|
6 | 8 | my $happy = 1; |
|
22 | 24 |
|
23 | 25 | # How many days to keep? |
24 | 26 | my $t = time() - ($savedays * 60 * 60 * 24); |
25 | | -print "Deleting anything before: " . strftime("%D", localtime($t)) . "\n"; |
26 | | -my $to_delete; |
| 27 | +print "Deleting anything in $dir before: " . strftime("%D", localtime($t)) . "\n"; |
| 28 | +my $to_delete = ""; |
27 | 29 |
|
28 | 30 | # Check everything in the dir; if is a dir, is not . or .., and is |
29 | 31 | # older than the save date, keep it for deleting later. |
30 | | -foreach my $file (@files) { |
31 | | - if (-f "$dir/$file" && $file ne "index.php" && $file ne "md5sums.txt" && $file ne "sha1sums.txt" && $file ne "latest_snapshot.txt" && $file ne "." && $file ne "..") { |
32 | | - my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
33 | | - $atime,$mtime,$ctime,$blksize,$blocks) = stat("$dir/$file"); |
34 | | - my $str = "SAVE"; |
35 | | - if ($mtime < $t) { |
36 | | - $to_delete = "$to_delete $dir/$file"; |
37 | | - $str = "DELETE"; |
| 32 | +foreach my $file (sort(@files)) { |
| 33 | + if ($file ne "index.php" && |
| 34 | + $file ne "md5sums.txt" && |
| 35 | + $file ne "sha1sums.txt" && |
| 36 | + $file ne "latest_snapshot.txt" && |
| 37 | + $file ne "." && |
| 38 | + $file ne "..") { |
| 39 | + my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
| 40 | + $atime,$mtime,$ctime,$blksize,$blocks) = stat("$dir/$file"); |
| 41 | + my $str = "SAVE"; |
| 42 | + if ($mtime < $t) { |
| 43 | + $to_delete = "$to_delete $dir/$file"; |
| 44 | + $str = "DELETE"; |
| 45 | + } |
| 46 | + print "Found $file: $str (mtime: " . strftime("%D", localtime($mtime)) . ")\n"; |
38 | 47 | } |
39 | | - print "Found dir ($str): $file (mtime: " . strftime("%D", localtime($mtime)) . ")\n"; |
40 | | - } |
41 | 48 | } |
42 | 49 |
|
43 | 50 | # If we found anything to delete, do so. |
|
0 commit comments