Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleancpan - keep only the newest version of a package in .cpan/build
- Loading branch information
Reini Urban
committed
Oct 2, 2011
1 parent
8f74262
commit f591d6f
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
#!/usr/bin/perl | |||
|
|||
use Cwd; | |||
use File::Path; | |||
my $pwd = cwd(); | |||
chdir "$ENV{HOME}/.cpan/build"; | |||
# keep only the latest dir | |||
opendir(my $dh, ".") or die; | |||
while (my $d = readdir $dh) { | |||
next unless -d $d; | |||
next if $d =~ /^\./; | |||
my $t = (stat($d))[9]; | |||
my $b = substr($d,0,-7); | |||
next if substr($d,-7,1) ne '-'; | |||
for (grep !/\.yml/, <$b*>) { | |||
next if $_ eq $d; | |||
my $t1 = (stat($_))[9]; | |||
if (-d $_ and $t1 < $t) { | |||
print "rm -rf \"$_*\"\n"; | |||
rmtree($_); | |||
unlink("$_.yml"); | |||
} elsif (-d $_) { | |||
$t = $t1; | |||
} | |||
} | |||
} | |||
closedir $dh; | |||
chdir $pwd; |