| 1 | package Win32::TarUtil; | ||||||||||||||||||||
| 2 | 1 | $Win32::TarUtil::VERSION = '0.02'; | |||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Archive::Extract; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | require Exporter; | |||||||||||||||||||
| 10 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 11 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw(tu_extract tu_wipe tu_copy) ] ); | |||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 13 | 1 | our @EXPORT = qw(); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub tu_extract { | ||||||||||||||||||
|
Subroutine
tu_extract: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 16 | 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 | ▶ | mkdir $out_dir or croak "can't mkdir out_dir '$out_dir' ($!)"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | unless (-f $arch) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | unless ($ok) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | croak "Can't extract '$arch' => '$out_dir'"; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | my @D = do { | |||||||||||||||||||
| 38 | 0 | ▶ | opendir my $dh, $out_dir or croak "Can't opendir '$arch' => '$out_dir'"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | ▶ | grep { $_ ne '.' and $_ ne '..' } readdir $dh; | ||||||||||||||||||
|
Condition0%0/3
$_ ne '.' && $_ ne '..'
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | unless (@D == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | croak "extract '$arch' => '$out_dir': invalid structure (".scalar(@D).")"; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | my $item = $out_dir.'\\'.$D[0]; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | unless (-d $item) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | croak "extract '$arch' => '$out_dir': directory not found ('$item')"; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | return $item; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | sub tu_wipe { | ||||||||||||||||||
|
Subroutine
tu_wipe: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 56 | 0 | my ($thing) = @_; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | $thing =~ s{/}'\\'xmsg; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | if (-e $thing) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | ▶ | if (-f $thing) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 62 | 0 | ▶ | unlink $thing or croak "Panic in tu_wipe('$thing'), can't unlink because $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | last unless -e $thing; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | select(undef, undef, undef, 0.25); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | ▶ | if (-e $thing) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub tu_copy { | ||||||||||||||||||
|
Subroutine
tu_copy: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 89 | 0 | my ($t_from, $t_to) = @_; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | s{/}'\\'xmsg for $t_from, $t_to; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | unless (-e $t_from) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | croak "Panic in transfer('$t_from', '$t_to'), source does not exist"; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | if (-e $t_to) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 0 | croak "Panic in transfer('$t_from', '$t_to'), target does exist"; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | if (-d $t_from) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 102 | 0 | ▶ | mkdir $t_to or croak "Panic in transfer('$t_from', '$t_to'), can't mkdir because $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||