line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::TarUtil; |
2
|
|
|
|
|
|
|
$Win32::TarUtil::VERSION = '0.02'; |
3
|
1
|
|
|
1
|
|
551
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
597
|
use Archive::Extract; |
|
1
|
|
|
|
|
148687
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
717
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(tu_extract tu_wipe tu_copy) ] ); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
13
|
|
|
|
|
|
|
our @EXPORT = qw(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub tu_extract { |
16
|
0
|
|
|
0
|
0
|
|
my $arch = $_[0]; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$arch =~ s{/}'\\'xmsg; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $out_dir = $ENV{'TEMP'}.'\\A_Out'; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
tu_wipe($out_dir); |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
mkdir $out_dir or croak "can't mkdir out_dir '$out_dir' ($!)"; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
unless (-f $arch) { |
27
|
0
|
|
|
|
|
|
croak "Can't find archive '$arch'"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $ae = Archive::Extract->new(archive => $arch); |
31
|
0
|
|
|
|
|
|
my $ok = $ae->extract(to => $out_dir); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
unless ($ok) { |
34
|
0
|
|
|
|
|
|
croak "Can't extract '$arch' => '$out_dir'"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @D = do { |
38
|
0
|
0
|
|
|
|
|
opendir my $dh, $out_dir or croak "Can't opendir '$arch' => '$out_dir'"; |
39
|
0
|
0
|
|
|
|
|
grep { $_ ne '.' and $_ ne '..' } readdir $dh; |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
unless (@D == 1) { |
43
|
0
|
|
|
|
|
|
croak "extract '$arch' => '$out_dir': invalid structure (".scalar(@D).")"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $item = $out_dir.'\\'.$D[0]; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
unless (-d $item) { |
49
|
0
|
|
|
|
|
|
croak "extract '$arch' => '$out_dir': directory not found ('$item')"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $item; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub tu_wipe { |
56
|
0
|
|
|
0
|
0
|
|
my ($thing) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$thing =~ s{/}'\\'xmsg; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if (-e $thing) { |
61
|
0
|
0
|
|
|
|
|
if (-f $thing) { |
|
|
0
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
unlink $thing or croak "Panic in tu_wipe('$thing'), can't unlink because $!"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif (-d $thing) { |
65
|
0
|
|
|
|
|
|
for (1..4) { |
66
|
0
|
|
|
|
|
|
my $text = ''; |
67
|
0
|
|
|
|
|
|
$text .= qq{del /s /q "$thing"\n}; |
68
|
0
|
|
|
|
|
|
$text .= qx{del /s /q "$thing" 2>&1}; |
69
|
0
|
|
|
|
|
|
$text .= "\n\n"; |
70
|
0
|
|
|
|
|
|
$text .= qq{rd /s /q "$thing"\n}; |
71
|
0
|
|
|
|
|
|
$text .= qx{rd /s /q "$thing" 2>&1}; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
last unless -e $thing; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
select(undef, undef, undef, 0.25); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if (-e $thing) { |
79
|
0
|
|
|
|
|
|
croak "Panic in tu_wipe('$thing'), has not disappeared as it should"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
|
croak "Panic in tu_wipe('$thing'), neither file nor dir"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub tu_copy { |
89
|
0
|
|
|
0
|
0
|
|
my ($t_from, $t_to) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
s{/}'\\'xmsg for $t_from, $t_to; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
unless (-e $t_from) { |
94
|
0
|
|
|
|
|
|
croak "Panic in transfer('$t_from', '$t_to'), source does not exist"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (-e $t_to) { |
98
|
0
|
|
|
|
|
|
croak "Panic in transfer('$t_from', '$t_to'), target does exist"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if (-d $t_from) { |
|
|
0
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
mkdir $t_to or croak "Panic in transfer('$t_from', '$t_to'), can't mkdir because $!"; |
103
|
0
|
|
|
|
|
|
my $text = qx{xcopy /s /q "$t_from" "$t_to" 2>&1} =~ s{\s+}' 'xmsgr =~ s{\A \s}''xmsr =~ s{\s \z}''xmsr; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif (-f $t_from) { |
106
|
0
|
|
|
|
|
|
my $text = qx{copy "$t_from" "$t_to" 2>&1} =~ s{\s+}' 'xmsgr =~ s{\A \s}''xmsr =~ s{\s \z}''xmsr; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
0
|
|
|
|
|
|
croak "Panic in transfer('$t_from', '$t_to'), neither file nor dir"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |