blib/lib/Net/FTP/Recursive.pm

filter: Statementstmt 7.1% 28 / 391 Branchbran 0.0% 0 / 316 Conditioncond 0.0% 0 / 99 MC/DCmcdc 0.0% 0 / 60 Subroutinesub 28.5% 8 / 28 Podpod 60.0% 6 / 10 totaltotal 4.6% 42 / 904 CC 202 SCAR 81.1
CC
202
Cov
3%
_rget
7310.0
_rput
2450.0
_rdir
650.0
CRAP 3329.6
↑ Summary
1 package Net::FTP::Recursive;
2  
3 1 ▶use Net::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Cwd 'getcwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw/@ISA $VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use vars qw/%options %filesSeen %dirsSeen %linkMap $success/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 @ISA = qw|Net::FTP|;
12 1 $VERSION = '2.04';
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
15 0 my $class = shift;
16  
17 0 my $ftp = new Net::FTP(@_);
18  
19 0 ▶ bless $ftp, $class if defined($ftp);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ftp 0 0 0
20  
21 0 return $ftp;
22 }
23  
24 #------------------------------------------------------------------
25 # - cd to directory, lcd to directory
26 # - grab all files, process symlinks according to options
27 #
28 # - foreach directory
29 # - create it unless options say to flatten
30 # - call function recursively.
31 # - cd .. unless options say to flatten
32 # - lcd ..
33 #
34 # -----------------------------------------------------------------
35  
36 0 ▶sub rget{
Subroutine rget: not called CC=2 SCAR=17.9
Pod documented
37 0 my $ftp = shift;
38  
39 0 %options = (
40 ParseSub => \&parse_files,
41 SymLinkIgnore => 1,
42 @_,
43 InitialDir => $ftp->pwd
44 ); #setup the options
45  
46 0 local %dirsSeen = ();
47 0 local %filesSeen = ();
48  
49 0 ▶ if ( $options{SymlinkFollow} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"SymlinkFollow"}) 0 0 0
50 0 $dirsSeen{ $ftp->pwd } = Cwd::cwd();
51 }
52  
53 0 local $success = '';
54  
55 0 $ftp->_rget(); #do the real work here
56  
57 0 return $success;
58 }
59  
60 0 ▶sub _rget {
Subroutine _rget: not called CC=85 SCAR=89.0
61 0 my($ftp) = shift;
62  
63 0 my @dirs;
64  
65 0 my @ls = $ftp->dir();
66  
67 0 my @files = $options{ParseSub}->( @ls );
68  
69 0 @files = grep { $_->filename =~ $options{MatchAll} } @files
70 0 ▶ if $options{MatchAll};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"MatchAll"} 0 0 0
71  
72 0 @files = grep { $_->filename !~ $options{OmitAll} } @files
73 0 ▶ if $options{OmitAll};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"OmitAll"} 0 0 0
74  
75 0 ▶ print STDERR join("\n", @ls), "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
76 if $ftp->debug;
77  
78 0 my $remote_pwd = $ftp->pwd;
79 0 my $local_pwd = Cwd::cwd();
80  
81 FILE:
82 0 foreach my $file (@files){
83 #used to make sure that if we're deleting the files, we
84 #successfully retrieved the file
85 0 my $get_success = 1;
86 0 my $filename = $file->filename();
87  
88 #if it's not a directory we just need to get the file.
89 0 ▶ if ( $file->is_plainfile() ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($file->is_plainfile) { } 0 0 0
elsif ($file->is_directory) { } 0 0 0
elsif ($file->is_symlink) { } 0 0 0
90  
91 0 ▶ if( ( $options{MatchFiles}
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"MatchFiles"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/ or $Net::FTP::Recursive::options{"OmitFiles"} and $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/) 0 0 0
Condition0%0/9
$Net::FTP::Recursive::options{"MatchFiles"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/ or $Net::FTP::Recursive::options{"OmitFiles"} and $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/
l!l&&r!l&&!r
000
$Net::FTP::Recursive::options{"MatchFiles"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/
!ll&&!rl&&r
000
$Net::FTP::Recursive::options{"OmitFiles"} and $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/
!ll&&!rl&&r
000
MC/DC0%0/4
$Net::FTP::Recursive::options{"MatchFiles"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/ or $Net::FTP::Recursive::options{"OmitFiles"} and $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/
$Net::FTP::Recursive::options{"MatchFiles"} not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/ $Net::FTP::Recursive::options{"OmitFiles"} $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/
Truth table0%0/7
A and not(B) or C and D
A= $Net::FTP::Recursive::options{"MatchFiles"}B= not $filename =~ /$Net::FTP::Recursive::options{"MatchFiles"}/C= $Net::FTP::Recursive::options{"OmitFiles"}D= $filename =~ /$Net::FTP::Recursive::options{"OmitFiles"}/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
92 and $filename !~ $options{MatchFiles} )
93 or
94 ( $options{OmitFiles}
95 and $filename =~ $options{OmitFiles} )){
96  
97 0 next FILE;
98 }
99  
100 0 ▶ if ( $options{FlattenTree} and $filesSeen{$filename} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'FlattenTree'} and $Net::FTP::Recursive::filesSeen{$filename}) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
$Net::FTP::Recursive::options{"FlattenTree"} $Net::FTP::Recursive::filesSeen{$filename}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"FlattenTree"}B= $Net::FTP::Recursive::filesSeen{$filename}
ABresult
0X0
100
111
101 0 ▶ print STDERR "Retrieving $filename as ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
102 "$filename.$filesSeen{$filename}.\n"
103 if $ftp->debug;
104  
105 0 $get_success = $ftp->get( $filename,
106 "$filename.$filesSeen{$filename}" );
107 } else {
108 0 ▶ print STDERR "Retrieving $filename.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
109 if $ftp->debug;
110  
111 0 $get_success = $ftp->get( $filename );
112 }
113  
114 0 ▶ $filesSeen{$filename}++ if $options{FlattenTree};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"FlattenTree"} 0 0 0
115  
116 0 ▶ if ( $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
117 0 ▶ if ( $options{CheckSizes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'CheckSizes'}) { } 0 0 0
118 0 ▶ if ( -e $filename and ( (-s $filename) == $file->size ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filename and -s $filename == $file->size) { } 0 0 0
Condition0%0/3
-e $filename and -s $filename == $file->size
!ll&&!rl&&r
000
MC/DC0%0/2
-e $filename and -s $filename == $file->size
-e $filename -s $filename == $file->size
Truth table0%0/3
A and B
A= -e $filenameB= -s $filename == $file->size
ABresult
0X0
100
111
119 0 $ftp->delete( $filename );
120 0 ▶ print STDERR "Deleting '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
121 if $ftp->debug;
122 } else {
123 0 ▶ print STDERR "Will not delete '$filename': ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
124 'remote file size and local file size ',
125 "do not match!\n"
126 if $ftp->debug;
127 }
128 } else {
129 0 ▶ if ( $get_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_success) { } 0 0 0
130 0 $ftp->delete( $filename );
131 0 ▶ print STDERR "Deleting '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
132 if $ftp->debug;
133 } else {
134 0 ▶ print STDERR "Will not delete '$filename': ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
135 "error retrieving file!\n"
136 if $ftp->debug;
137 }
138 }
139 }
140 }
141 elsif ( $file->is_directory() ) {
142  
143 0 ▶ if( ( $options{MatchDirs}
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"MatchDirs"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/ or $Net::FTP::Recursive::options{"OmitDirs"} and $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/) 0 0 0
Condition0%0/9
$Net::FTP::Recursive::options{"MatchDirs"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/ or $Net::FTP::Recursive::options{"OmitDirs"} and $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/
l!l&&r!l&&!r
000
$Net::FTP::Recursive::options{"MatchDirs"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/
!ll&&!rl&&r
000
$Net::FTP::Recursive::options{"OmitDirs"} and $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/
!ll&&!rl&&r
000
MC/DC0%0/4
$Net::FTP::Recursive::options{"MatchDirs"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/ or $Net::FTP::Recursive::options{"OmitDirs"} and $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/
$Net::FTP::Recursive::options{"MatchDirs"} not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/ $Net::FTP::Recursive::options{"OmitDirs"} $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/
Truth table0%0/7
A and not(B) or C and D
A= $Net::FTP::Recursive::options{"MatchDirs"}B= not $filename =~ /$Net::FTP::Recursive::options{"MatchDirs"}/C= $Net::FTP::Recursive::options{"OmitDirs"}D= $filename =~ /$Net::FTP::Recursive::options{"OmitDirs"}/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
144 and $filename !~ $options{MatchDirs} )
145 or
146 ( $options{OmitDirs}
147 and $filename =~ $options{OmitDirs} )){
148  
149 0 next FILE;
150 }
151  
152 0 ▶ if ( $options{SymlinkFollow} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"SymlinkFollow"}) 0 0 0
153 0 $dirsSeen{"$remote_pwd/$filename"} = "$local_pwd/$filename";
154 0 print STDERR "Mapping '$remote_pwd/$filename' to ",
155 "'$local_pwd/$filename'.\n";
156 }
157  
158 0 push @dirs, $file;
159 }
160 elsif ( $file->is_symlink() ) {
161  
162 #SymlinkIgnore is really the default.
163 0 ▶ if ( $options{SymlinkIgnore} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"SymlinkIgnore"}) 0 0 0
164 0 ▶ print STDERR "Ignoring the symlink ", $filename, ".\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
165 if $ftp->debug;
166 0 ▶ if ( $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
167 0 $ftp->delete( $filename );
168 0 ▶ print STDERR 'Deleting \'', $filename, "'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
169 if $ftp->debug;
170 }
171 0 next FILE;
172 }
173  
174 0 ▶ if( ( $options{MatchLinks}
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"MatchLinks"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/ or $Net::FTP::Recursive::options{"OmitLinks"} and $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/) 0 0 0
Condition0%0/9
$Net::FTP::Recursive::options{"MatchLinks"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/ or $Net::FTP::Recursive::options{"OmitLinks"} and $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/
l!l&&r!l&&!r
000
$Net::FTP::Recursive::options{"MatchLinks"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/
!ll&&!rl&&r
000
$Net::FTP::Recursive::options{"OmitLinks"} and $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/
!ll&&!rl&&r
000
MC/DC0%0/4
$Net::FTP::Recursive::options{"MatchLinks"} and not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/ or $Net::FTP::Recursive::options{"OmitLinks"} and $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/
$Net::FTP::Recursive::options{"MatchLinks"} not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/ $Net::FTP::Recursive::options{"OmitLinks"} $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/
Truth table0%0/7
A and not(B) or C and D
A= $Net::FTP::Recursive::options{"MatchLinks"}B= not $filename =~ /$Net::FTP::Recursive::options{"MatchLinks"}/C= $Net::FTP::Recursive::options{"OmitLinks"}D= $filename =~ /$Net::FTP::Recursive::options{"OmitLinks"}/
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
175 and $filename !~ $options{MatchLinks} )
176 or
177 ( $options{OmitLinks}
178 and $filename =~ $options{OmitLinks} )){
179  
180 0 next FILE;
181 }
182  
183 #otherwise we need to see if it points to a directory
184 0 ▶ print STDERR "Testing to see if $filename refers to a directory.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
185 if $ftp->debug;
186 0 my $path_before_chdir = $ftp->pwd;
187 0 my $is_directory = 0;
188  
189 0 ▶ if ( $ftp->cwd($file->filename()) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->cwd($file->filename)) 0 0 0
190 0 $ftp->cwd( $path_before_chdir );
191 0 $is_directory = 1;
192 }
193  
194 0 ▶ if ( not $is_directory and $options{SymlinkCopy} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $is_directory and $Net::FTP::Recursive::options{'SymlinkCopy'}) { } 0 0 0
elsif ($is_directory and $Net::FTP::Recursive::options{'SymlinkFollow'}) { } 0 0 0
elsif ($Net::FTP::Recursive::options{'SymlinkLink'}) { } 0 0 0
Condition0%0/3
not $is_directory and $Net::FTP::Recursive::options{"SymlinkCopy"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_directory and $Net::FTP::Recursive::options{"SymlinkCopy"}
not $is_directory $Net::FTP::Recursive::options{"SymlinkCopy"}
Truth table0%0/3
not(A) and B
A= not $is_directoryB= $Net::FTP::Recursive::options{"SymlinkCopy"}
ABresult
0X0
100
111
195 #if it's not a directory and SymlinkCopy is set,
196 # we'll just copy the file as a regular file
197  
198 #symlink to non-directory. need to grab it and
199 #make sure the filename does not collide
200 0 my $get_success;
201 0 ▶ if ( $options{FlattenTree} and $filesSeen{$filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'FlattenTree'} and $Net::FTP::Recursive::filesSeen{$filename}) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
$Net::FTP::Recursive::options{"FlattenTree"} $Net::FTP::Recursive::filesSeen{$filename}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"FlattenTree"}B= $Net::FTP::Recursive::filesSeen{$filename}
ABresult
0X0
100
111
202 print STDERR "Retrieving $filename as ",
203 0 ▶ $filename.$filesSeen{$filename},
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
204 ".\n"
205 if $ftp->debug;
206  
207 0 $get_success = $ftp->get($filename,
208 "$filename.$filesSeen{$filename}");
209 } else {
210 0 ▶ print STDERR "Retrieving $filename.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
211 if $ftp->debug;
212  
213 0 $get_success = $ftp->get( $filename );
214 }
215  
216 0 $filesSeen{$filename}++;
217  
218 0 ▶ if ( $get_success and $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_success and $Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
Condition0%0/3
$get_success and $Net::FTP::Recursive::options{"RemoveRemoteFiles"}
!ll&&!rl&&r
000
MC/DC0%0/2
$get_success and $Net::FTP::Recursive::options{"RemoveRemoteFiles"}
$get_success $Net::FTP::Recursive::options{"RemoveRemoteFiles"}
Truth table0%0/3
A and B
A= $get_successB= $Net::FTP::Recursive::options{"RemoveRemoteFiles"}
ABresult
0X0
100
111
219 0 $ftp->delete( $filename );
220  
221 0 ▶ print STDERR "Deleting '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
222 if $ftp->debug;
223 }
224 } #end of if (not $is_directory and $options{SymlinkCopy}
225 ▶ elsif ( $is_directory and $options{SymlinkFollow} ) {
Condition0%0/3
$is_directory and $Net::FTP::Recursive::options{"SymlinkFollow"}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_directory and $Net::FTP::Recursive::options{"SymlinkFollow"}
$is_directory $Net::FTP::Recursive::options{"SymlinkFollow"}
Truth table0%0/3
A and B
A= $is_directoryB= $Net::FTP::Recursive::options{"SymlinkFollow"}
ABresult
0X0
100
111
226 #we need to resolve the link to an absolute path
227  
228 0 my $remote_abs_path = path_resolve( $file->linkname(),
229 $remote_pwd,
230 $filename
231 );
232  
233 0 print STDERR "'$filename' got converted to '",
234 $remote_abs_path, "'.\n";
235  
236 #if it's a directory structure we've already seen,
237 #we'll just make a relative symlink to that
238 #directory
239  
240 # OR
241  
242 #if it's in the same tree that we started
243 #downloading, we should get to it later, so we'll
244 #just make a relative symlink to that directory.
245  
246 0 ▶ if ( $dirsSeen{$remote_abs_path}
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ s/^$Net::FTP::Recursive::options{'InitialDir'}/$Net::FTP::Recursive::dirsSeen{$Net::FTP::Recursive::options{'InitialDir'}}/) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ s/^$Net::FTP::Recursive::options{"InitialDir"}/$Net::FTP::Recursive::dirsSeen{$Net::FTP::Recursive::options{"InitialDir"}}/
l!l&&r!l&&!r
000
MC/DC0%0/2
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ s/^$Net::FTP::Recursive::options{"InitialDir"}/$Net::FTP::Recursive::dirsSeen{$Net::FTP::Recursive::options{"InitialDir"}}/
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} $remote_abs_path =~ s/^$Net::FTP::Recursive::options{"InitialDir"}/$Net::FTP::Recursive::dirsSeen{$Net::FTP::Recursive::options{"InitialDir"}}/
Truth table0%0/3
A or B
A= $Net::FTP::Recursive::dirsSeen{$remote_abs_path}B= $remote_abs_path =~ s/^$Net::FTP::Recursive::options{"InitialDir"}/$Net::FTP::Recursive::dirsSeen{$Net::FTP::Recursive::options{"InitialDir"}}/
ABresult
1X1
011
000
247 or $remote_abs_path =~ s{^$options{InitialDir}}
248 {$dirsSeen{$options{InitialDir}}}){
249  
250 0 ▶ unless( $options{FlattenTree} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::FTP::Recursive::options{"FlattenTree"}) 0 0 0
251 print STDERR "\$dirsSeen{$remote_abs_path} = ",
252 0 ▶ $dirsSeen{$remote_abs_path}, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
253 if $ftp->debug;
254  
255 print STDERR "Calling convert_to_relative( '",
256 $local_pwd, '/', $filename, "', '",
257 0 ▶ ( $dirsSeen{$remote_abs_path}
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
Condition0%0/3
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} || $remote_abs_path
l!l&&r!l&&!r
000
MC/DC0%0/2
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} || $remote_abs_path
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} $remote_abs_path
Truth table0%0/3
A || B
A= $Net::FTP::Recursive::dirsSeen{$remote_abs_path}B= $remote_abs_path
ABresult
1X1
011
000
258 || $remote_abs_path ),
259 "');\n"
260 if $ftp->debug;
261  
262 my $rel_path =
263 convert_to_relative( "$local_pwd/$filename",
264 0 ▶ $dirsSeen{$remote_abs_path}
Condition0%0/3
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} || $remote_abs_path
l!l&&r!l&&!r
000
MC/DC0%0/2
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} || $remote_abs_path
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} $remote_abs_path
Truth table0%0/3
A || B
A= $Net::FTP::Recursive::dirsSeen{$remote_abs_path}B= $remote_abs_path
ABresult
1X1
011
000
265 || $remote_abs_path
266 );
267  
268 0 ▶ print STDERR "Symlinking '$filename' to '$rel_path'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
269 if $ftp->debug;
270  
271 0 symlink $rel_path, $filename;
272 }
273  
274 0 ▶ if ( $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
275 0 $ftp->delete( $filename );
276  
277 0 ▶ print STDERR "Deleting '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
278 if $ftp->debug;
279 }
280  
281 0 next FILE;
282 }
283 # Otherwise we need to grab the directory and put
284 # the info in a hash in case there is another link
285 # to this directory
286 else {
287  
288 0 ▶ print STDERR "New directory to grab!\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
289 if $ftp->debug;
290 0 push @dirs, $file;
291  
292 0 $dirsSeen{$remote_abs_path} = "$local_pwd/$filename";
293 0 ▶ print STDERR "Mapping '$remote_abs_path' to '",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
294 "$local_pwd/$filename'.\n"
295 if $ftp->debug;
296 #no deletion, will handle that down below.
297  
298 }
299  
300 } #end of elsif($is_directory and $options{SymlinkFollow})
301  
302 # if it's a dir and SymlinkFollow is not set but
303 # SymlinkLink is set, we'll just create the link.
304  
305 # OR
306  
307 # if it was a file and SymlinkCopy is not set but
308 # SymlinkLink is, we'll just create the link.
309  
310 elsif ( $options{SymlinkLink} ) {
311 #we need to make the symlink and that's it.
312 0 symlink $file->linkName(), $file->filename();
313  
314 0 ▶ if ( $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
315 0 $ftp->delete( $file->filename );
316  
317 0 ▶ print STDERR "Deleting '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
318 if $ftp->debug;
319 }
320 0 next FILE;
321 }
322 }
323  
324 0 ▶ $success .= "Had a problem retrieving '$remote_pwd/$filename'!\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $get_success 0 0 0
325 unless $get_success;
326 } #end of foreach ( @files )
327  
328 0 undef @files; #save memory in recursing.
329  
330 #this will do depth-first retrieval
331  
332 DIRECTORY:
333 0 foreach my $file (@dirs) {
334 0 my $filename = $file->filename;
335  
336 #check to make sure that we actually have permissions to
337 #change into the directory
338  
339 0 ▶ unless ( $ftp->cwd($filename) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($filename)) 0 0 0
340 0 ▶ print STDERR 'Was unable to cd to ', $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
341 ", skipping!\n"
342 if $ftp->debug;
343  
344 0 $success .= "Was not able to chdir to '$remote_pwd/$filename'!\n";
345 0 next DIRECTORY;
346 }
347  
348 0 ▶ unless ( $options{FlattenTree} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::FTP::Recursive::options{"FlattenTree"}) 0 0 0
349 0 ▶ print STDERR "Making dir: ", $filename, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
350 if $ftp->debug;
351  
352 0 mkdir $filename, "0755"; # mkdir, ignore errors due to
353 # pre-existence
354  
355 0 chmod 0755, $filename; # just in case the UMASK in the
356 # mkdir doesn't work
357  
358 0 ▶ unless ( chdir $filename ){
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $filename) 0 0 0
359 0 ▶ print STDERR 'Could not change to the local directory ',
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
360 $filename, "!\n"
361 if $ftp->debug;
362  
363 0 $ftp->cwd( $remote_pwd );
364 0 $success .= q{Could not chdir to local directory '}
365 . "$local_pwd/$filename'!\n";
366  
367 0 next DIRECTORY;
368 }
369 }
370  
371 #don't delete files that are accessed through a symlink
372  
373 0 my $remove;
374 0 ▶ if ( $options{RemoveRemoteFiles} and $file->is_symlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"} and $file->is_symlink) 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"RemoveRemoteFiles"} and $file->is_symlink
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"RemoveRemoteFiles"} and $file->is_symlink
$Net::FTP::Recursive::options{"RemoveRemoteFiles"} $file->is_symlink
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"RemoveRemoteFiles"}B= $file->is_symlink
ABresult
0X0
100
111
375 0 $remove = $options{RemoveRemoteFiles};
376 0 $options{RemoveRemoteFiles} = 0;
377 }
378  
379 #need to recurse
380 0 ▶ print STDERR 'Calling rget in ', $remote_pwd, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
381 if $ftp->debug;
382 0 $ftp->_rget( );
383  
384 #once we've recursed, we'll go back up a dir.
385 0 ▶ print STDERR 'Returned from rget in ', $remote_pwd, ".\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
386 if $ftp->debug;
387  
388 0 ▶ if ( $file->is_symlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->is_symlink) { } 0 0 0
389 0 $ftp->cwd( $remote_pwd );
390 0 $options{RemoveRemoteFiles} = $remove;
391 } else {
392 0 $ftp->cdup;
393 }
394  
395 0 ▶ chdir '..' unless $options{FlattenTree};
Branch: 1 branch
BranchTrueFalseTotal
unless $Net::FTP::Recursive::options{"FlattenTree"} 0 0 0
396  
397 0 ▶ if ( $options{RemoveRemoteFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveRemoteFiles"}) 0 0 0
398 0 ▶ if ( $file->is_symlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->is_symlink) { } 0 0 0
399 0 ▶ print STDERR "Removing symlink '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
400 if $ftp->debug;
401  
402 0 $ftp->delete( $filename );
403 } else {
404 0 ▶ print STDERR "Removing directory '$filename'.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
405 if $ftp->debug;
406  
407 0 $ftp->rmdir( $filename );
408 }
409 }
410 }
411 }
412  
413 0 ▶sub rput{
Subroutine rput: not called CC=1 SCAR=6.9
Pod documented
414 0 my $ftp = shift;
415  
416 0 %options = (
417 ParseSub => \&parse_files,
418 @_
419 );
420  
421 0 local %filesSeen = ();
422  
423 0 local $success = '';
424  
425 0 $ftp->_rput(); #do the real work here
426  
427 0 return $success;
428 }
429  
430 #------------------------------------------------------------------
431 # - make the directory on the remote host
432 # - cd to directory, lcd to directory
433 # - foreach directory, call the function recursively
434 # - cd .., lcd ..
435 # -----------------------------------------------------------------
436  
437 0 ▶sub _rput {
Subroutine _rput: not called CC=49 SCAR=78.0
438 0 my($ftp) = shift;
439  
440 0 my @dirs; #list of directories to recurse into after this dir is processed
441  
442 0 my @files = read_current_directory();
443  
444 0 ▶ print STDERR join("\n", sort map { $_->filename() } @files),"\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
445 if $ftp->debug;
446  
447 0 my $remote_pwd = $ftp->pwd;
448  
449 0 foreach my $file (@files){
450 0 my $put_success = 1;
451 0 my $filename = $file->filename(); #we're gonna need it a lot here
452  
453 #if it's a file we just need to put the file
454 0 ▶ if ( $file->is_plainfile() ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($file->is_plainfile) { } 0 0 0
elsif ($file->is_directory) { } 0 0 0
elsif ($file->is_symlink) { } 0 0 0
455  
456 #we're going to check for filename conflicts here if
457 #the user has opted to flatten out the tree
458 0 ▶ if ( $options{FlattenTree} and $filesSeen{$filename} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'FlattenTree'} and $Net::FTP::Recursive::filesSeen{$filename}) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
$Net::FTP::Recursive::options{"FlattenTree"} $Net::FTP::Recursive::filesSeen{$filename}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"FlattenTree"}B= $Net::FTP::Recursive::filesSeen{$filename}
ABresult
0X0
100
111
459 0 ▶ print STDERR "Sending $filename as ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
460 "$filename.$filesSeen{$filename}.\n"
461 if $ftp->debug;
462 0 $put_success = $ftp->put( $filename,
463 "$filename.$filesSeen{$filename}" );
464 } else {
465 0 ▶ print STDERR "Sending $filename.\n" if $ftp->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
466  
467 #I've saved $put_success here, but apparently the
468 #return val isn't very useful-can probably stop
469 #saving it
470 0 $put_success = $ftp->put( $filename );
471 }
472  
473 0 ▶ $filesSeen{$filename}++ if $options{FlattenTree};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"FlattenTree"} 0 0 0
474  
475 0 ▶ if ( $options{RemoveLocalFiles} and $options{CheckSizes} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'RemoveLocalFiles'} and $Net::FTP::Recursive::options{'CheckSizes'}) { } 0 0 0
elsif ($Net::FTP::Recursive::options{'RemoveLocalFiles'}) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"RemoveLocalFiles"} and $Net::FTP::Recursive::options{"CheckSizes"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"RemoveLocalFiles"} and $Net::FTP::Recursive::options{"CheckSizes"}
$Net::FTP::Recursive::options{"RemoveLocalFiles"} $Net::FTP::Recursive::options{"CheckSizes"}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"RemoveLocalFiles"}B= $Net::FTP::Recursive::options{"CheckSizes"}
ABresult
0X0
100
111
476 0 ▶ if ( $ftp->size($filename) == (-s $filename) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->size($filename) == -s $filename) { } 0 0 0
477 0 ▶ print STDERR q{Removing '}, $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
478 "' from the local system.\n"
479 if $ftp->debug;
480  
481 0 unlink $file->filename();
482 } else {
483 0 ▶ print STDERR "Will not delete '$filename': ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
484 'remote file size and local file size',
485 " do not match!\n"
486 if $ftp->debug;
487 }
488 }
489 elsif( $options{RemoveLocalFiles} ) {
490 0 ▶ print STDERR q{Removing '}, $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
491 "' from the local system.\n"
492 if $ftp->debug;
493 0 unlink $file->filename();
494 }
495 }
496  
497 #otherwise, if it's a directory, we have to create the directory
498 #on the remote machine, cd to it, then recurse
499  
500 elsif ( $file->is_directory() ) {
501 0 push @dirs, $file;
502 }
503  
504 #if it's a symlink, there's nothing we can do with it.
505 elsif ( $file->is_symlink() ) {
506  
507 0 ▶ if ( $options{SymlinkIgnore} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'SymlinkIgnore'}) { } 0 0 0
508 0 ▶ print STDERR "Not doing anything to ", $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
509 " as it is a link.\n"
510 if $ftp->debug;
511  
512 0 ▶ if ( $options{RemoveLocalFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"RemoveLocalFiles"}) 0 0 0
513 0 ▶ print STDERR q{Removing '}, $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
514 "' from the local system.\n"
515 if $ftp->debug;
516  
517 0 unlink $file->filename();
518 }
519 }
520 else {
521 # check to see what kind of file the link target is
522 0 ▶ if ( -f $filename and $options{SymlinkCopy} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $filename and $Net::FTP::Recursive::options{'SymlinkCopy'}) { } 0 0 0
elsif (-d $file->filename and $Net::FTP::Recursive::options{'SymlinkFollow'}) { } 0 0 0
Condition0%0/3
-f $filename and $Net::FTP::Recursive::options{"SymlinkCopy"}
!ll&&!rl&&r
000
MC/DC0%0/2
-f $filename and $Net::FTP::Recursive::options{"SymlinkCopy"}
-f $filename $Net::FTP::Recursive::options{"SymlinkCopy"}
Truth table0%0/3
A and B
A= -f $filenameB= $Net::FTP::Recursive::options{"SymlinkCopy"}
ABresult
0X0
100
111
523 0 ▶ if ( $options{FlattenTree} and $filesSeen{$filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'FlattenTree'} and $Net::FTP::Recursive::filesSeen{$filename}) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"FlattenTree"} and $Net::FTP::Recursive::filesSeen{$filename}
$Net::FTP::Recursive::options{"FlattenTree"} $Net::FTP::Recursive::filesSeen{$filename}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"FlattenTree"}B= $Net::FTP::Recursive::filesSeen{$filename}
ABresult
0X0
100
111
524 0 ▶ print STDERR "Sending $filename as ",
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
525 "$filename.$filesSeen{$filename}.\n"
526 if $ftp->debug;
527  
528 0 $put_success = $ftp->put( $filename,
529 "$filename.$filesSeen{$filename}" );
530  
531 } else {
532 0 ▶ print STDERR "Sending $filename.\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
533 if $ftp->debug;
534  
535 0 $put_success = $ftp->put( $filename );
536 }
537  
538 0 ▶ $filesSeen{$filename}++ if $options{FlattenTree};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"FlattenTree"} 0 0 0
539  
540 0 ▶ if ( $put_success and $options{RemoveLocalFiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($put_success and $Net::FTP::Recursive::options{"RemoveLocalFiles"}) 0 0 0
Condition0%0/3
$put_success and $Net::FTP::Recursive::options{"RemoveLocalFiles"}
!ll&&!rl&&r
000
MC/DC0%0/2
$put_success and $Net::FTP::Recursive::options{"RemoveLocalFiles"}
$put_success $Net::FTP::Recursive::options{"RemoveLocalFiles"}
Truth table0%0/3
A and B
A= $put_successB= $Net::FTP::Recursive::options{"RemoveLocalFiles"}
ABresult
0X0
100
111
541 0 ▶ print STDERR q{Removing '}, $filename,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
542 "' from the local system.\n"
543 if $ftp->debug;
544  
545 0 unlink $file->filename();
546 }
547 }
548 ▶ elsif ( -d $file->filename() and $options{SymlinkFollow} ) {
Condition0%0/3
-d $file->filename and $Net::FTP::Recursive::options{"SymlinkFollow"}
!ll&&!rl&&r
000
MC/DC0%0/2
-d $file->filename and $Net::FTP::Recursive::options{"SymlinkFollow"}
-d $file->filename $Net::FTP::Recursive::options{"SymlinkFollow"}
Truth table0%0/3
A and B
A= -d $file->filenameB= $Net::FTP::Recursive::options{"SymlinkFollow"}
ABresult
0X0
100
111
549 #then it's a directory, we need to add it to the
550 #list of directories to grab
551 0 push @dirs, $file;
552 }
553 }
554 }
555  
556 0 ▶ $success .= "Had trouble putting $filename into $remote_pwd\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $put_success 0 0 0
557 unless $put_success;
558  
559 }
560  
561 0 undef @files; #save memory in recursing.
562  
563 # we'll use an absolute path to chdir at the end.
564 0 my $local_pwd = Cwd::cwd();
565  
566 0 foreach my $file (@dirs) {
567  
568 0 my $filename = $file->filename();
569  
570 0 ▶ unless ( chdir $filename ){
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $filename) 0 0 0
571 0 ▶ print STDERR 'Could not change to the local directory ',
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
572 $filename, "!\n"
573 if $ftp->debug;
574  
575 0 $success .= 'Could not change to the local directory '
576 . qq{'$local_pwd/$filename'!\n};
577 0 next;
578 }
579  
580 # try to chdir to the remote path, if it's not possible,
581 # try to make the directory instead
582 0 ▶ unless( $ftp->cwd($filename) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($filename)) 0 0 0
583 0 ▶ print STDERR "Making dir: ", $filename, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
584 if $ftp->debug;
585  
586 0 ▶ unless( $ftp->mkdir($filename) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->mkdir($filename)) 0 0 0
587 0 ▶ print STDERR 'Could not make remote directory ',
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
588 $filename, "!\n"
589 if $ftp->debug;
590  
591 0 $success .= q{Could not make remote directory '}
592 . qq{$remote_pwd/$filename}
593 . qq{!\n};
594 }
595  
596 0 ▶ unless ( $ftp->cwd($filename) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($filename)) 0 0 0
597 0 ▶ print STDERR 'Could not change remote directory to ',
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
598 $filename, ", skipping!\n"
599 if $ftp->debug;
600  
601 0 $success .= qq{Could not change remote directory to '}
602 . qq{$remote_pwd/$filename}
603 . qq{'!\n};
604 0 next;
605 }
606 }
607  
608 0 ▶ print STDERR "Calling rput in ", $local_pwd, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
609 if $ftp->debug;
610 0 $ftp->_rput();
611  
612 #once we've recursed, we'll go back up a dir.
613 0 ▶ print STDERR 'Returned from rput in ',
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
614 $filename, ".\n"
615 if $ftp->debug;
616  
617 0 $ftp->cdup;
618  
619 0 ▶ if ( $file->is_symlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->is_symlink) { } 0 0 0
620 0 chdir $local_pwd;
621 0 ▶ unlink $filename if $options{RemoveLocalFiles};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"RemoveLocalFiles"} 0 0 0
622 } else {
623 0 chdir '..';
624 0 ▶ rmdir $filename if $options{RemoveLocalFiles};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"RemoveLocalFiles"} 0 0 0
625 }
626 }
627 }
628  
629  
630 0 ▶sub rdir{
Subroutine rdir: not called CC=2 SCAR=17.9
Pod documented
631 0 my($ftp) = shift;
632  
633 0 %options = ( ParseSub => \&parse_files,
634 OutputFormat => '%p %lc %u %g %s %d %f %l',
635 @_,
636 InitialDir => $ftp->pwd
637 ); #setup the options
638  
639 0 ▶ unless( $options{Filehandle} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::FTP::Recursive::options{"Filehandle"}) 0 0 0
640 0 Carp::croak("You must pass a filehandle when using rdelete/rls!");
641 }
642  
643 0 local %dirsSeen = ();
644 0 local %filesSeen = ();
645  
646 0 $dirsSeen{$ftp->pwd}++;
647  
648 0 local $success = '';
649  
650 0 $ftp->_rdir;
651  
652 0 return $success;
653 }
654  
655 0 ▶sub _rdir{
Subroutine _rdir: not called CC=25 SCAR=64.8
656 0 my $ftp = shift;
657  
658 0 my @ls = $ftp->dir;
659  
660 0 ▶ print STDERR join("\n", @ls) if $ftp->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
661  
662 0 my(@dirs);
663 0 my $fh = $options{Filehandle};
664 0 ▶ print $fh $ftp->pwd, ":\n" unless $options{FilenameOnly};
Branch: 1 branch
BranchTrueFalseTotal
unless $Net::FTP::Recursive::options{"FilenameOnly"} 0 0 0
665  
666 0 my $remote_pwd = $ftp->pwd;
667 0 my $local_pwd = Cwd::cwd();
668  
669 LINE:
670 0 foreach my $line ( @ls ) {
671 0 my($file) = $options{ParseSub}->( $line );
672 0 ▶ next LINE unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
673  
674 0 my $filename = $file->filename;
675  
676 # if it's a symlink that points to a directory, we need to
677 # check it for cycles, and then put it on the list of directories
678 # to examine
679  
680 0 ▶ if ( $file->is_symlink() and $ftp->cwd($filename) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file->is_symlink and $ftp->cwd($filename)) { } 0 0 0
elsif ($file->is_directory) { } 0 0 0
Condition0%0/3
$file->is_symlink and $ftp->cwd($filename)
!ll&&!rl&&r
000
MC/DC0%0/2
$file->is_symlink and $ftp->cwd($filename)
$file->is_symlink $ftp->cwd($filename)
Truth table0%0/3
A and B
A= $file->is_symlinkB= $ftp->cwd($filename)
ABresult
0X0
100
111
681 0 $ftp->cwd( $remote_pwd );
682  
683 #we need to resolve the link to an absolute path
684 0 my $remote_abs_path = path_resolve( $file->linkname,
685 $remote_pwd,
686 $filename );
687  
688 0 print STDERR qq{'$filename' got converted to '$remote_abs_path'.\n};
689  
690 #if it's a directory structure we've already seen,
691 #we'll just treat it as a regular file
692  
693 # OR
694  
695 #if it's in the same tree that we started
696 #downloading, we should get to it later, so we'll
697 #just treat it as a regular file
698  
699 0 ▶ unless ( $dirsSeen{$remote_abs_path}
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ /^$Net::FTP::Recursive::options{"InitialDir"}/) 0 0 0
Condition0%0/3
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ /^$Net::FTP::Recursive::options{"InitialDir"}/
l!l&&r!l&&!r
000
MC/DC0%0/2
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} or $remote_abs_path =~ /^$Net::FTP::Recursive::options{"InitialDir"}/
$Net::FTP::Recursive::dirsSeen{$remote_abs_path} $remote_abs_path =~ /^$Net::FTP::Recursive::options{"InitialDir"}/
Truth table0%0/3
A or B
A= $Net::FTP::Recursive::dirsSeen{$remote_abs_path}B= $remote_abs_path =~ /^$Net::FTP::Recursive::options{"InitialDir"}/
ABresult
1X1
011
000
700 or $remote_abs_path =~ m%^$options{InitialDir}% ){
701  
702 # Otherwise we need to grab the directory and put
703 # the info in a hash in case there is another link
704 # to this directory
705  
706 0 push @dirs, $file;
707 0 $dirsSeen{$remote_abs_path}++;
708  
709 0 ▶ if( $ftp->debug() ){
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->debug) 0 0 0
710 print STDERR q{Mapping '},
711 $remote_abs_path,
712 q{' to '},
713 0 $dirsSeen{$remote_abs_path},
714 ".\n";
715 }
716 }
717 }
718 elsif ( $file->is_directory() ) {
719 0 push @dirs, $file;
720  
721 #since we won't get to the code below, we need this
722 #code here
723 0 ▶ if ( $options{FilenameOnly} && $options{PrintType} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"FilenameOnly"} and $Net::FTP::Recursive::options{"PrintType"}) 0 0 0
Condition0%0/3
$Net::FTP::Recursive::options{"FilenameOnly"} and $Net::FTP::Recursive::options{"PrintType"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::options{"FilenameOnly"} and $Net::FTP::Recursive::options{"PrintType"}
$Net::FTP::Recursive::options{"FilenameOnly"} $Net::FTP::Recursive::options{"PrintType"}
Truth table0%0/3
A and B
A= $Net::FTP::Recursive::options{"FilenameOnly"}B= $Net::FTP::Recursive::options{"PrintType"}
ABresult
0X0
100
111
724 0 print $fh $remote_pwd, '/', $filename, " d\n";
725 }
726  
727 0 ▶ next LINE if $options{FilenameOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $Net::FTP::Recursive::options{"FilenameOnly"} 0 0 0
728 }
729  
730  
731 0 ▶ if( $options{FilenameOnly} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{'FilenameOnly'}) { } 0 0 0
732 0 print $fh $remote_pwd, '/', $filename;
733 0 ▶ if ( $options{PrintType} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Recursive::options{"PrintType"}) 0 0 0
734 0 my $filetype;
735 0 ▶ if ( $file->is_symlink() ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file->is_symlink) { } 0 0 0
elsif ($file->is_plainfile) { } 0 0 0
736 0 print $fh ' s';
737 } elsif ( $file->is_plainfile() ) {
738 0 print $fh ' f';
739 }
740 }
741 0 print $fh "\n";
742 }
743 else {
744 0 print $fh $line, "\n";
745 }
746 }
747  
748 0 ▶ print $fh "\n" unless $options{FilenameOnly};
Branch: 1 branch
BranchTrueFalseTotal
unless $Net::FTP::Recursive::options{"FilenameOnly"} 0 0 0
749  
750 0 foreach my $dir (@dirs){
751 0 my $dirname = $dir->filename;
752  
753 0 ▶ unless ( $ftp->cwd( $dirname ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($dirname)) 0 0 0
754 0 ▶ print STDERR 'Was unable to cd to ', $dirname,
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
755 " in $remote_pwd, skipping!\n"
756 if $ftp->debug;
757 0 $success .= qq{Was unable to cd to '$remote_pwd/$dirname'\n};
758 0 next;
759 }
760  
761 0 ▶ print STDERR "Calling rdir in ", $remote_pwd, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
762 if $ftp->debug;
763 0 $ftp->_rdir( );
764  
765 #once we've recursed, we'll go back up a dir.
766 0 ▶ print STDERR "Returned from rdir in ", $dirname, ".\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
767 if $ftp->debug;
768  
769 0 ▶ if ( $dir->is_symlink() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir->is_symlink) { } 0 0 0
770 0 $ftp->cwd($remote_pwd);
771 }
772 else {
773 0 $ftp->cdup;
774 }
775 }
776 }
777  
778 0 ▶sub rls{
Subroutine rls: not called CC=1 SCAR=6.9
Pod documented
779 0 my $ftp = shift;
780 0 return $ftp->rdir(@_, FilenameOnly => 1);
781 }
782  
783 #---------------------------------------------------------------
784 # CD to directory
785 # Recurse through all subdirectories and delete everything
786 # This will not go into symlinks
787 #---------------------------------------------------------------
788  
789 0 ▶sub rdelete {
Subroutine rdelete: not called CC=1 SCAR=6.9
Pod documented
790  
791 0 my($ftp) = shift;
792  
793 0 %options = ( ParseSub => \&parse_files,
794 @_
795 ); #setup the options
796  
797 0 local $success = '';
798  
799 0 $ftp->_rdelete(); #do the real work here
800  
801 0 return $success;
802  
803 }
804  
805 0 ▶sub _rdelete {
Subroutine _rdelete: not called CC=13 SCAR=52.0
806  
807 0 my $ftp = shift;
808  
809 0 my @dirs;
810  
811 0 my @ls = $ftp->dir;
812  
813 0 ▶ print STDERR join("\n", @ls) if $ftp->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
814  
815 0 my $remote_pwd = $ftp->pwd;
816  
817 0 foreach my $line ( @ls ){
818 0 my($file) = $options{ParseSub}->($line);
819  
820 #just delete plain files and symlinks
821 0 ▶ if ( $file->is_plainfile() or $file->is_symlink() ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file->is_plainfile or $file->is_symlink) { } 0 0 0
elsif ($file->is_directory) { } 0 0 0
Condition0%0/3
$file->is_plainfile or $file->is_symlink
l!l&&r!l&&!r
000
MC/DC0%0/2
$file->is_plainfile or $file->is_symlink
$file->is_plainfile $file->is_symlink
Truth table0%0/3
A or B
A= $file->is_plainfileB= $file->is_symlink
ABresult
1X1
011
000
822 0 my $filename = $file->filename();
823 0 my $del_success = $ftp->delete($filename);
824  
825 0 ▶ $success .= qq{Had a problem deleting '$remote_pwd/$filename'!\n}
Branch: 1 branch
BranchTrueFalseTotal
unless $del_success 0 0 0
826 unless $del_success;
827 }
828 #otherwise, if it's a directory, we have more work to do.
829 elsif ( $file->is_directory() ) {
830 0 push @dirs, $file;
831 }
832 }
833  
834 #this will do depth-first delete
835 0 foreach my $file (@dirs) {
836 0 my $filename = $file->filename();
837  
838 #in case we didn't have permissions to cd into that
839 #directory
840 0 ▶ unless ( $ftp->cwd( $file->filename() ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->cwd($file->filename)) 0 0 0
841 0 ▶ print STDERR qq{Could not change dir to $filename!\n}
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
842 if $ftp->debug;
843 0 $success .= qq{Could not change dir to '$remote_pwd/$filename'!\n};
844 0 next;
845 }
846  
847 #need to recurse
848 0 ▶ print STDERR 'Calling _rdelete in ', $ftp->pwd, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
849 if $ftp->debug;
850 0 $ftp->_rdelete( );
851  
852 #once we've recursed, we'll go back up a dir.
853 0 ▶ print STDERR "Returned from _rdelete in ", $ftp->pwd, ".\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->debug 0 0 0
854 if $ftp->debug;
855 0 $ftp->cdup;
856  
857 ##now delete the directory we just came out of
858 0 ▶ $ftp->rmdir($file->filename())
Branch: 1 branch
BranchTrueFalseTotal
$ftp->rmdir($file->filename) or $Net::FTP::Recursive::success .= 'Could not delete remote directory "' . "$remote_pwd/$filename" . qq["!\n] 0 0 0
859 or $success .= 'Could not delete remote directory "'
860 . qq{$remote_pwd/$filename}
861 . qq{"!\n};
862 }
863 }
864  
865 #-------------------------------------------------------------#
866 #
867 # read_current_directory()
868 #
869 # Used by the _rput() method to retrieve the list of local
870 # files to send to the remote server. This eliminates the need
871 # to use "ls" or "dir" to read the local directory and then parse
872 # the output from those commands.
873 #
874 #-------------------------------------------------------------#
875 0 ▶sub read_current_directory {
Subroutine read_current_directory: not called CC=8 SCAR=42.8
Pod undocumented
876 0 ▶ opendir THISDIR, '.' or die "Couldn't open ", getcwd();
Branch: 1 branch
BranchTrueFalseTotal
opendir THISDIR, "." or die "Couldn't open ", getcwd() 0 0 0
877  
878 0 my $path = getcwd();
879  
880 0 my @to_return;
881  
882 0 foreach my $file ( sort readdir(THISDIR) ){
883 0 ▶ next if $file =~ /^[.]{1,2}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^[.]{1,2}$/ 0 0 0
884  
885 0 my $file_obj;
886  
887 # checking for the symlink must come first; -d and -f can resolve
888 # to true if the link points to either a dir or a plain file
889 0 ▶ if( -l $file ){
Branch: 3 branches
BranchTrueFalseTotal
if (-l $file) { } 0 0 0
elsif (-d $file) { } 0 0 0
elsif (-f $file) { } 0 0 0
890 0 $file_obj
891 = Net::FTP::Recursive::File->new(
892 'symlink' => 1,
893 filename => $file,
894 path => $path,
895 linkname => readlink($file),
896 );
897 }
898 elsif( -d $file ){
899 0 $file_obj = Net::FTP::Recursive::File->new(
900 directory => 1,
901 filename => $file,
902 path => $path,
903 );
904 }
905 elsif( -f $file ){
906 0 $file_obj = Net::FTP::Recursive::File->new(
907 plainfile => 1,
908 filename => $file,
909 path => $path,
910 );
911 }
912  
913 0 ▶ push @to_return, $file_obj if $file_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $file_obj 0 0 0
914 }
915  
916 0 closedir THISDIR;
917  
918 0 return @to_return;
919 }
920  
921 #-------------------------------------------------------------------#
922 # Should look at all of the output from the current dir and parse
923 # through and extract the filename, date, size, and whether it is a
924 # directory or not
925 #
926 # The date should also have a time, so that if the script needs to be
927 # run several times in one day, it will grab any files that changed
928 # that day.
929 #-------------------------------------------------------------------#
930  
931 0 ▶sub parse_files {
Subroutine parse_files: not called CC=7 SCAR=40.3
Pod undocumented
932 0 my(@to_return) = ();
933  
934 0 foreach my $line (@_) {
935 0 ▶ next unless $line =~ /^
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^ (\S+)\s+ #permissions \d+\s+ #link count \S+\s+ #user owner \S+\s+ #group owner \d+\s+ #size \w+\s+\w+\s+\S+\s+ #last modification date (.+?)\s* #filename (?:->\s*(.+))? #optional link part $ /x 0 0 0
936 (\S+)\s+ #permissions
937 \d+\s+ #link count
938 \S+\s+ #user owner
939 \S+\s+ #group owner
940 \d+\s+ #size
941 \w+\s+\w+\s+\S+\s+ #last modification date
942 (.+?)\s* #filename
943 (?:->\s*(.+))? #optional link part
944 $
945 /x;
946  
947 0 my($perms, $filename, $linkname) = ($1, $2, $3);
948  
949 0 ▶ next if $filename =~ /^\.{1,2}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /^\.{1,2}$/ 0 0 0
950  
951 0 my $file;
952 0 ▶ if ($perms =~/^-/){
Branch: 3 branches
BranchTrueFalseTotal
if ($perms =~ /^-/) { } 0 0 0
elsif ($perms =~ /^d/) { } 0 0 0
elsif ($perms =~ /^l/) { } 0 0 0
953 0 $file = Net::FTP::Recursive::File->new( plainfile => 1,
954 filename => $filename );
955 }
956 elsif ($perms =~ /^d/) {
957 0 $file = Net::FTP::Recursive::File->new( directory => 1,
958 filename => $filename );
959 } elsif ($perms =~/^l/) {
960 0 $file = Net::FTP::Recursive::File->new( 'symlink' => 1,
961 filename => $filename,
962 linkname => $linkname );
963 } else {
964 0 next; #didn't match, skip the file
965 }
966  
967 0 push(@to_return, $file);
968 }
969  
970 0 return(@to_return);
971 }
972  
973 =begin blah
974  
975 This subroutine takes a path and converts the '.' and
976 '..' parts of it to make it into a proper absolute path.
977  
978 =end blah
979  
980 =cut
981  
982 0 ▶sub path_resolve{
Subroutine path_resolve: not called CC=6 SCAR=37.4
Pod undocumented
983 0 my($link_path, $pwd, $filename) = @_;
984 0 my $remote_pwd; #value to return
985  
986 #this case is so that if we have gotten to this
987 #symlink through another symlink, we can actually
988 #retrieve the correct files (make the correct
989 #symlink, whichever)
990  
991 0 ▶ if ( $linkMap{$pwd} and $link_path !~ m#^/# ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Recursive::linkMap{$pwd} and not $link_path =~ m[^/]) { } 0 0 0
elsif ($link_path =~ m[^/]) { } 0 0 0
Condition0%0/3
$Net::FTP::Recursive::linkMap{$pwd} and not $link_path =~ m[^/]
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Recursive::linkMap{$pwd} and not $link_path =~ m[^/]
$Net::FTP::Recursive::linkMap{$pwd} not $link_path =~ m[^/]
Truth table0%0/3
A and not(B)
A= $Net::FTP::Recursive::linkMap{$pwd}B= not $link_path =~ m[^/]
ABresult
0X0
100
111
992 0 $remote_pwd = $linkMap{$pwd} . '/' . $link_path;
993 }
994  
995 # if it was an absolute path, just make sure there aren't
996 # any . or .. in it, and make sure it ends with a /
997 elsif ( $link_path =~ m#^/# ) {
998 0 $remote_pwd = $link_path;
999 }
1000  
1001 #otherwise, it was a relative path and we need to
1002 #prepend the current working directory onto it and
1003 #then eliminate any .. or . that are present
1004 else {
1005 0 $remote_pwd = $pwd;
1006 0 $remote_pwd =~ s#(?<!/)$#/#;
1007 0 $remote_pwd .= $link_path;
1008 }
1009  
1010 #Collapse the resulting path if it has . or .. in it. The
1011 #while loop is needed to make it start over after each
1012 #match (as it will need to go back for parts of the
1013 #regex). It's probably possible to write a regex to do it
1014 #without the while loop, but I don't think that making it
1015 #less readable is a good idea. :)
1016  
1017 0 ▶ while ( $remote_pwd =~ s#(?:^|/)\.(?:/|$)#/# ) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($remote_pwd =~ s[(?:^|/)\.(?:/|$)][/]) 0 0 0
1018 0 ▶ while ( $remote_pwd =~ s#(?:/[^/]+)?/\.\.(?:/|$)#/# ){}
Branch: 1 branch
BranchTrueFalseTotal
if ($remote_pwd =~ s[(?:/[^/]+)?/\.\.(?:/|$)][/]) 0 0 0
1019  
1020 #the %linkMap will store as keys the absolute paths
1021 #to the links and the values will be the "real"
1022 #absolute paths to those locations (to take care of
1023 #../-type links
1024  
1025 0 $filename =~ s#/$##;
1026 0 $remote_pwd =~ s#/$##;
1027  
1028 0 $pwd =~ s#(?<!/)$#/#; #make sure there's a / on the end
1029 0 $linkMap{$pwd . $filename} = $remote_pwd;
1030  
1031 0 $remote_pwd; #return the result
1032 }
1033  
1034 =begin comment
1035  
1036 This subroutine takes two absolute paths and basically
1037 'links' them together. The idea is that all of the paths
1038 that are created for the symlinks should be relative
1039 paths. This is the sub that does that.
1040  
1041 There are essentially 6 cases:
1042  
1043 -Different root hierarchy:
1044 /tmp/testdata/blah -> /usr/local/bin/blah
1045 -Current directory:
1046 /tmp/testdata/blah -> /tmp/testdata
1047 -A file in the current directory:
1048 /tmp/testdata/blah -> /tmp/testdata/otherblah
1049 -Lower in same hierarchy:
1050 /tmp/testdata/blah -> /tmp/testdata/dir/otherblah
1051 -A higher directory along the same path (part of link abs path) :
1052 /tmp/testdata/dir/dir2/otherblah -> /tmp/testdata/dir
1053 -In same hierarchy, somewhere else:
1054 /tmp/testdata/dir/dir2/otherblah -> /tmp/testdata/dir/file
1055  
1056 The last two cases are very similar, the only difference
1057 will be that it will create '../' for the first rather
1058 than the possible '../../dir'. The last case will indeed
1059 get the '../file'.
1060  
1061 =end comment
1062  
1063 =cut
1064  
1065 0 ▶sub convert_to_relative{
Subroutine convert_to_relative: not called CC=10 SCAR=47.0
Pod undocumented
1066 0 my($link_loc, $realfile) = (shift, shift);
1067 0 my $i;
1068 my $result;
1069 0 my($new_realfile, $new_link, @realfile_parts, @link_parts);
1070  
1071 0 @realfile_parts = split m#/#, $realfile;
1072 0 @link_parts = split m#/#, $link_loc;
1073  
1074 0 ▶ for ( $i = 0; $i < @realfile_parts; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @realfile_parts) 0 0 0
1075 0 ▶ last unless $realfile_parts[$i] eq $link_parts[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $realfile_parts[$i] eq $link_parts[$i] 0 0 0
1076 }
1077  
1078 0 $new_realfile = join '/', @realfile_parts[$i..$#realfile_parts];
1079 0 $new_link = join '/', @link_parts[$i..$#link_parts];
1080  
1081 0 ▶ if( $i == 1 ){
Branch: 4 branches
BranchTrueFalseTotal
if ($i == 1) { } 0 0 0
elsif ($i > $#realfile_parts and $i == $#link_parts) { } 0 0 0
elsif ($i == $#realfile_parts and $i == $#link_parts) { } 0 0 0
elsif ($i >= $#link_parts) { } 0 0 0
1082 0 $result = $realfile;
1083 }
1084 ▶ elsif ( $i > $#realfile_parts and $i == $#link_parts ) {
Condition0%0/3
$i > $#realfile_parts and $i == $#link_parts
!ll&&!rl&&r
000
MC/DC0%0/2
$i > $#realfile_parts and $i == $#link_parts
$i > $#realfile_parts $i == $#link_parts
Truth table0%0/3
A and B
A= $i > $#realfile_partsB= $i == $#link_parts
ABresult
0X0
100
111
1085 0 $result = '.';
1086 }
1087 ▶ elsif ( $i == $#realfile_parts and $i == $#link_parts ) {
Condition0%0/3
$i == $#realfile_parts and $i == $#link_parts
!ll&&!rl&&r
000
MC/DC0%0/2
$i == $#realfile_parts and $i == $#link_parts
$i == $#realfile_parts $i == $#link_parts
Truth table0%0/3
A and B
A= $i == $#realfile_partsB= $i == $#link_parts
ABresult
0X0
100
111
1088 0 $result = $realfile_parts[$i];
1089 }
1090 elsif ( $i >= $#link_parts ) {
1091 0 $result = join '/', @realfile_parts[$i..$#realfile_parts];
1092 }
1093 else {
1094 0 $result = '../' x ($#link_parts - $i);
1095 0 ▶ $result .= join '/', @realfile_parts[$i..$#realfile_parts]
Branch: 1 branch
BranchTrueFalseTotal
if $#link_parts - $i > 0 0 0 0
1096 if $#link_parts - $i > 0;
1097 }
1098  
1099 0 return $result;
1100 }
1101  
1102  
1103 package Net::FTP::Recursive::File;
1104  
1105 1 ▶use vars qw/@ISA/;
Subroutine BEGIN: called CC=1 SCAR=0.0
1106 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
1107  
1108 1 @ISA = ();
1109  
1110 0 ▶sub new{
Subroutine new: not called CC=4 SCAR=30.0
1111 0 my $pkg = shift;
1112  
1113 0 my $self = { plainfile => 0,
1114 directory => 0,
1115 'symlink' => 0,
1116 @_
1117 };
1118  
1119 croak 'Must set a filename when creating a File object!'
1120 0 ▶ unless defined $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"filename"} 0 0 0
1121  
1122 0 ▶ if( $self->{'symlink'} and not $self->{linkname} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"symlink"} and not $self->{"linkname"}) 0 0 0
Condition0%0/3
$self->{"symlink"} and not $self->{"linkname"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"symlink"} and not $self->{"linkname"}
$self->{"symlink"} not $self->{"linkname"}
Truth table0%0/3
A and not(B)
A= $self->{"symlink"}B= not $self->{"linkname"}
ABresult
0X0
100
111
1123 0 croak 'Must set a linkname when creating a File object for a symlink!';
1124 }
1125  
1126 0 bless $self, $pkg;
1127 }
1128  
1129 0 ▶sub linkname{
Subroutine linkname: not called CC=1 SCAR=6.9
1130 0 return $_[0]->{linkname};
1131 }
1132  
1133 0 ▶sub filename{
Subroutine filename: not called CC=1 SCAR=6.9
1134 0 return $_[0]->{filename};
1135 }
1136  
1137 0 ▶sub is_symlink{
Subroutine is_symlink: not called CC=1 SCAR=6.9
1138 0 return $_[0]->{symlink};
1139 }
1140  
1141 0 ▶sub is_directory{
Subroutine is_directory: not called CC=1 SCAR=6.9
1142 0 return $_[0]->{directory};
1143 }
1144  
1145 0 ▶sub is_plainfile{
Subroutine is_plainfile: not called CC=1 SCAR=6.9
1146 0 return $_[0]->{plainfile};
1147 }
1148  
1149 1 1;
1150  
1151 __END__
↑ Summary