-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack-dists.pl
executable file
·42 lines (38 loc) · 1.24 KB
/
unpack-dists.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl
use strict;
use warnings;
use Archive::Tar;
use Cwd qw( getcwd realpath );
use CPAN::DistnameInfo;
use constant SOURCEDIR => ( getcwd . '/dists' );
use constant TARGETDIR => ( getcwd . '/dists-unpacked' );
open my $dist_fh, '<', 'dists.list' or die "Can't open dists.list";
while ( my $dist = <$dist_fh> ) {
chomp $dist;
$dist =~ s/#.*$//;
next if $dist =~ /^\s*$/;
my $info = CPAN::DistnameInfo->new($dist);
my $newname = $info->dist . '.' . $info->extension;
my $infile = SOURCEDIR . '/' . $newname;
if ( not -e $infile ) {
warn "* $infile does not exist, not unpacking\n";
next;
}
my $outdir = TARGETDIR . '/' . $info->dist;
if ( -e $outdir ) {
$outdir = realpath($outdir);
warn "* $outdir already exists, purging\n";
if ( 30 > length $outdir or 3 > scalar split q[/], $outdir ) {
warn "! $outdir TOO SUSPICIOUS, not removing\n";
next
}
system("rm", "-r", "-v", $outdir ) == 0 or die "rm failed!";
}
mkdir $outdir or die "Can't make $outdir";
{
my $ref = getcwd();
chdir $outdir or die "Can't enter $outdir";
system("tar", "-x", "-f", $infile , "--strip-components=1" );
chdir $ref or die "Can't leave $outdir";
}
}