| 1 | package CopyTree::VendorProof::LocalFileOp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | #our @ISA = qw(CopyTree::VendorProof); #if this weren't commented out, the use base below won't work | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.0013'; | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use base qw(CopyTree::VendorProof);#for the @ISAs | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | #use base happens at compile time, so we don't get the runtime error of our, saying that | ||||||||||||||||||||||||||||
| 16 | #Can't locate package CopyTree::VendorProof for @SharePoint::SOAPHandler::ISA at (eval 8) line 2. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 1 | my $class =shift; | |||||||||||||||||||||||||||
| 23 | 1 | my $path = shift; | |||||||||||||||||||||||||||
| 24 | 1 | ▶ | $path =~s/\/$// unless (!$path or $path eq '/'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $path or $path eq "/"
MC/DC0%0/2
not $path or $path eq "/"
not $path
$path eq "/"
Truth table33%1/3
not(A) or B
A= not $pathB= $path eq "/"
| |||||||||||||||||||||||||||||
| 25 | 1 | my $hashref; | |||||||||||||||||||||||||||
| 26 | 1 | $hashref = bless {path => $path}, $class; | |||||||||||||||||||||||||||
| 27 | 1 | return $hashref; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #lists files and / or dirs of a dir | ||||||||||||||||||||||||||||
| 31 | 7 | ▶ | sub fdls { | ||||||||||||||||||||||||||
|
Subroutine
fdls: called CC=12 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 7 | my $inst = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 7 | ▶ | unless (ref $inst ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | Carp::croak("fdls item must be an instance, not a class\n"); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 7 | my $lsoption =shift; | |||||||||||||||||||||||||||
| 38 | 7 | my $path =shift; | |||||||||||||||||||||||||||
| 39 | 7 | ▶ | $path =~s/\/$// unless (!$path or $path eq '/'); #removes trailing / | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $path or $path eq "/"
MC/DC0%0/2
not $path or $path eq "/"
not $path
$path eq "/"
Truth table33%1/3
not(A) or B
A= not $pathB= $path eq "/"
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 7 | ▶ | $lsoption ='' if !($lsoption); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 7 | ▶ | $path = $inst ->SUPER::path if (!$path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 7 | my $dirH; | |||||||||||||||||||||||||||
| 44 | 7 | ▶ | opendir ($dirH, $path) or Carp::carp ("ERROR in local_ls cannot open dirH to $path $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 7 | my @itemsnoparent =readdir $dirH; | |||||||||||||||||||||||||||
| 46 | 7 | closedir $dirH; | |||||||||||||||||||||||||||
| 47 | 7 | my @results; | |||||||||||||||||||||||||||
| 48 | my @files; | ||||||||||||||||||||||||||||
| 49 | 7 | my @dirs; | |||||||||||||||||||||||||||
| 50 | 7 | for (@itemsnoparent){ | |||||||||||||||||||||||||||
| 51 | 74 | ▶ | next if ($_ eq '.' or $_ eq '..'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ eq "." or $_ eq ".."
MC/DC100%2/2
$_ eq "." or $_ eq ".."
$_ eq "."
$_ eq ".."
Truth table100%3/3
A or B
A= $_ eq "."B= $_ eq ".."
| |||||||||||||||||||||||||||||
| 52 | 60 | ▶ | push @files, $path.'/'.$_ if (-f "$path/$_"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 60 | ▶ | push @dirs, $path.'/'.$_ if (-d "$path/$_"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 7 | $inst ->SUPER::fdls_ret ($lsoption, \@files, \@dirs); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 26 | ▶ | sub is_fd{ | ||||||||||||||||||||||||||
|
Subroutine
is_fd: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 26 | my $class_inst=shift; | |||||||||||||||||||||||||||
| 60 | 26 | my $query = shift; | |||||||||||||||||||||||||||
| 61 | 26 | ▶ | if (-d $query){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 62 | 6 | return 'd'; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | elsif (-f $query){ | ||||||||||||||||||||||||||||
| 65 | 12 | return 'f'; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||
| 68 | 8 | my $parent = File::Basename::dirname($query); | |||||||||||||||||||||||||||
| 69 | 8 | ▶ | if (-d $parent){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 7 | return 'pd'; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 1 | else{return 0} | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | #memory is a ref to a scalar, in bin mode | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub read_into_memory{ | ||||||||||||||||||||||||||
|
Subroutine
read_into_memory: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 1 | my $inst=shift; | |||||||||||||||||||||||||||
| 78 | 1 | my $sourcepath = shift; | |||||||||||||||||||||||||||
| 79 | 1 | ▶ | $sourcepath =~s/\/$// unless $sourcepath eq '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | $sourcepath=$inst->SUPER::path if (!$sourcepath); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | my $binfile; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | open my $readFH, "<", $sourcepath or Carp::carp("cannot read sourcepath [$sourcepath] $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 1 | binmode ($readFH); | |||||||||||||||||||||||||||
| 84 | {#slurp | ||||||||||||||||||||||||||||
| 85 | 1 | local $/ =undef; | |||||||||||||||||||||||||||
| 86 | 1 | $binfile = <$readFH>; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 1 | close $readFH; | |||||||||||||||||||||||||||
| 89 | 1 | return \$binfile; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | #memory is a ref to a scalar, in bin mode | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub write_from_memory{ | ||||||||||||||||||||||||||
|
Subroutine
write_from_memory: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 1 | my $inst=shift; | |||||||||||||||||||||||||||
| 95 | 1 | my $bincontentref = shift; | |||||||||||||||||||||||||||
| 96 | 1 | my $dest = shift; | |||||||||||||||||||||||||||
| 97 | 1 | ▶ | $dest = $inst ->SUPER::path if (!$dest); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | open my $outFH, ">","$dest" or Carp::carp("cannot write to dest [$dest] $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 1 | binmode ($outFH); | |||||||||||||||||||||||||||
| 100 | 1 | print $outFH $$bincontentref ; | |||||||||||||||||||||||||||
| 101 | 1 | close $outFH; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub copy_local_files { | ||||||||||||||||||||||||||
|
Subroutine
copy_local_files: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 6 | my $inst = shift; | |||||||||||||||||||||||||||
| 108 | 6 | my $source = shift; | |||||||||||||||||||||||||||
| 109 | 6 | my $dest = shift; | |||||||||||||||||||||||||||
| 110 | 6 | ▶ | open my $inFH, "<", $source or Carp::carp( "cannot open source fh $source $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 6 | ▶ | open my $ouFH, ">", $dest or Carp::carp( "cannot open dest fh $dest $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 6 | binmode ($inFH); | |||||||||||||||||||||||||||
| 113 | 6 | binmode ($ouFH); | |||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 6 | local $/=undef; #slurp | |||||||||||||||||||||||||||
| 116 | 6 | my $content = <$inFH>; | |||||||||||||||||||||||||||
| 117 | 6 | print $ouFH $content; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 6 | close $inFH; | |||||||||||||||||||||||||||
| 120 | 6 | close $ouFH; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 4 | ▶ | sub cust_mkdir{ | ||||||||||||||||||||||||||
|
Subroutine
cust_mkdir: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 4 | my $inst = shift; | |||||||||||||||||||||||||||
| 125 | 4 | my $path = shift; | |||||||||||||||||||||||||||
| 126 | 4 | ▶ | Carp::croak( "should not be mkdiring a root [/]\n" )unless $path ne '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 3 | $path =~s/\/$// ; # purposefully disallow mkdir / unless $path eq '/'; | |||||||||||||||||||||||||||
| 128 | 3 | ▶ | mkdir $path or Carp::carp ("cannot mkdir $path $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 4 | ▶ | sub cust_rmdir{ | ||||||||||||||||||||||||||
|
Subroutine
cust_rmdir: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 4 | my $inst = shift; | |||||||||||||||||||||||||||
| 133 | 4 | my $path = shift; | |||||||||||||||||||||||||||
| 134 | 4 | ▶ | Carp::croak( "should not be rmdiring a root [/]\n" )unless $path ne '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 3 | $path =~s/\/$// ; # purposefully disallow rmdir / unless $path eq '/'; | |||||||||||||||||||||||||||
| 136 | 3 | ▶ | unless (rmdir $path){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 3 | Carp::carp( "the dir [$path] you want to remove is NOT EMPTY $!\n"); | |||||||||||||||||||||||||||
| 138 | 3 | ▶ | Carp::croak( "wait. you told me to delete something that's not a dir. I'll stop for your protection.\n") if (! -d $path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 2 | my ($files, $dirs) = $inst ->ls_tree_fdret($path, $inst ->ls_tree($path) ); | |||||||||||||||||||||||||||
| 140 | 2 | print Dumper $files; | |||||||||||||||||||||||||||
| 141 | 2 | print Dumper $dirs; | |||||||||||||||||||||||||||
| 142 | 2 | Carp::carp( "danger - going to take out the whole tree under [$path]\n"); | |||||||||||||||||||||||||||
| 143 | 2 | Carp::carp( "going to wait 3 seconds. use Ctrl-c to escape this. Hold down the Ctrl key, and hit 'c'.\n"); | |||||||||||||||||||||||||||
| 144 | 2 | sleep 3; | |||||||||||||||||||||||||||
| 145 | 2 | for (@$files){ | |||||||||||||||||||||||||||
| 146 | 6 | ▶ | unlink $_ or Carp::carp ("cannot unlink $_ $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 2 | for (@$dirs){ | |||||||||||||||||||||||||||
| 149 | 1 | ▶ | rmdir $_ or Carp::carp ("cannot rmdir $_ $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 2 | rmdir $path; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 2 | ▶ | sub cust_rmfile { | ||||||||||||||||||||||||||
|
Subroutine
cust_rmfile: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 2 | my $inst=shift; | |||||||||||||||||||||||||||
| 156 | 2 | my $filepath=shift; | |||||||||||||||||||||||||||
| 157 | 2 | ▶ | Carp::croak("[$filepath] is not a file") if (! -f $filepath); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 2 | unlink $filepath; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | 1; | |||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||