| 1 | package Zucchini::Fsync; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | $Zucchini::Fsync::VERSION = '0.0.21'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | $Zucchini::Fsync::DIST = 'Zucchini'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: move files using FTP | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # vim: ts=8 sts=4 et sw=4 sr sta | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use strict; # for kwalitee testing | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use MooX::Types::MooseLike::Base qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Zucchini::Types qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Config::Any; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use File::Slurp qw(read_file write_file); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use File::Temp qw( tempfile ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use Path::Class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # class data | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | has config => ( | |||||||||||||||||||||||||||||||||||||||||
| 25 | reader => 'get_config', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | writer => 'set_config', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | isa => ZucchiniConfig, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | has ftp_client => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | reader => 'get_ftp_client', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | writer => 'set_ftp_client', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => NetFTP, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | has ftp_root => ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | reader => 'get_ftp_root', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | writer => 'set_ftp_root', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | has remote_digest => ( | |||||||||||||||||||||||||||||||||||||||||
| 43 | reader => 'get_remote_digest', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | writer => 'set_remote_digest', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # set up an ftp client/connection to work with | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | if (defined $self->get_config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $self->prepare_ftp_client; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub build_transfer_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_transfer_actions: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($local_digest_file, $remote_digest_file); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($local_md5_of, $remote_md5_of, %transfer_action_of); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # the two files we are going to compare | ||||||||||||||||||||||||||||||||||||||||||
| 65 | $local_digest_file = file( | ||||||||||||||||||||||||||||||||||||||||||
| 66 | $config->{output_dir}, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | q{digest.md5} | |||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $remote_digest_file = file( | |||||||||||||||||||||||||||||||||||||||||
| 70 | $self->get_remote_digest | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $local_md5_of = $self->parse_md5file($local_digest_file); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $remote_md5_of = $self->parse_md5file($remote_digest_file) || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parse_md5file($remote_digest_file) || {}
MC/DC0%0/1
$self->parse_md5file($remote_digest_file) || {}
$self->parse_md5file($remote_digest_file)
Truth table0%0/2
A
A= $self->parse_md5file($remote_digest_file)
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # run through the list of files we have locally | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | foreach my $relpath ( | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | sort { length($a) <=> length($b) } keys %{$local_md5_of} | |||||||||||||||||||||||||||||||||||||||||
| 79 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $dirname = dirname($relpath); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $parentdir = dir($dirname)->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # make sure our parent directory exists | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # (prevents problems with nested dirs that contain no files) | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | while ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
".." ne $parentdir and not exists $transfer_action_of{$parentdir}
MC/DC0%0/2
".." ne $parentdir and not exists $transfer_action_of{$parentdir}
".." ne $parentdir
not exists $transfer_action_of{$parentdir}
Truth table0%0/3
A and not(B)
A= ".." ne $parentdirB= not exists $transfer_action_of{$parentdir}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | q{..} ne $parentdir | ||||||||||||||||||||||||||||||||||||||||||
| 87 | and | ||||||||||||||||||||||||||||||||||||||||||
| 88 | not exists $transfer_action_of{$parentdir} | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # this is effectively a NO-OP that gets the directory name | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # into the list of (required) remote directories | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | push @{$transfer_action_of{$parentdir}}, | |||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | action => 'dir-dir', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | # recurse upwards | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $parentdir = $parentdir->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # does the file live in the server? | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (exists $remote_md5_of->{$relpath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | # if the MD5s match - nothing to do | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($local_md5_of->{$relpath} eq $remote_md5_of->{$relpath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | delete $local_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | delete $remote_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | push @{$transfer_action_of{$dirname}}, | |||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | action => 'update', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | relname => $relpath, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | delete $local_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | delete $remote_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # ... it's a new file to put on the server | ||||||||||||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | push @{$transfer_action_of{$dirname}}, | |||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | action => 'new', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | relname => $relpath, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | delete $local_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # anything left in remote is a file we don't have locally | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # we'll store actions (remove) for these, but won't act on the | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # action until specifically asked | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | foreach my $relpath (sort keys %{$remote_md5_of}) { | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $dirname = dirname($relpath); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | push @{$transfer_action_of{$dirname}}, | |||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | action => 'remove', | ||||||||||||||||||||||||||||||||||||||||||
| 137 | relname => $relpath, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | delete $remote_md5_of->{$relpath}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # make sure we didn't miss anything | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (keys %{$local_md5_of}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | warn qq{Some local files were not processed}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | warn qq{Local: } . pp($local_md5_of); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if (keys %{$remote_md5_of}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | warn qq{Some remote files were not processed}; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | warn qq{Remote: } . pp($remote_md5_of); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return \%transfer_action_of; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub do_remote_update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_remote_update: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $transfer_actions = shift; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $ftp = $self->get_ftp_client; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $ftp_root = $self->get_ftp_root; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if (not defined $ftp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | warn(qq{No FTP server defined. Aborting upload.\n}); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # do transfer actions shortest dirname first | ||||||||||||||||||||||||||||||||||||||||||
| 169 | my @remote_dirs = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | length($a) <=> length($b) | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | } keys %{$transfer_actions}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $ftp_root_status = $ftp->cwd($ftp_root); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (not $ftp_root_status) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | die "$ftp_root: couldn't CWD to remote directory\n"; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $default_dir = $ftp->pwd(); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($default_dir !~ m{/\z}xms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $default_dir .= q{/}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | # make missing (remote) directories | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | warn "checking remote directories...\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | if ($self->get_config->verbose(1)); | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | foreach my $dir (@remote_dirs) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $status = $ftp->cwd($default_dir . $dir); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (not $status) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | # verbose ouput | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | warn (q{MKDIR } . dir($default_dir, $dir) . qq{\n}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | if ($self->get_config->verbose(1)); | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # make the missing directory | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if (not $ftp->mkdir($default_dir . $dir)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | warn ( | |||||||||||||||||||||||||||||||||||||||||
| 194 | q{FAILED MKDIR } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | . dir($default_dir, $dir) | ||||||||||||||||||||||||||||||||||||||||||
| 196 | . q{ - } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | . $ftp->message | ||||||||||||||||||||||||||||||||||||||||||
| 198 | . qq{\n}); | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # return to the default location | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $ftp->cwd($default_dir); | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | # now run through everything and take the appropriate action for files | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | warn "transferring files...\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | if ($self->get_config->verbose(1)); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | foreach my $dir (@remote_dirs) { | |||||||||||||||||||||||||||||||||||||||||
| 209 | # run through the actions for the directory | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | foreach my $action ( @{$transfer_actions->{$dir}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($action->{action} =~ m{\A(?:new|update)\z}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | # verbose ouput | ||||||||||||||||||||||||||||||||||||||||||
| 213 | warn ( | ||||||||||||||||||||||||||||||||||||||||||
| 214 | q{PUT } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | . $action->{relname} | ||||||||||||||||||||||||||||||||||||||||||
| 216 | . q{ } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | . $action->{relname} | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | . qq{\n} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 220 | if ($self->get_config->verbose(1)); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # send the file | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if (not $ftp->put( $action->{relname}, $action->{relname} )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $errors++; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | warn "failed to upload $action->{relname}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 225 | warn ( | ||||||||||||||||||||||||||||||||||||||||||
| 226 | q{FAILED PUT } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | . $action->{relname} | ||||||||||||||||||||||||||||||||||||||||||
| 228 | . q{ } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | . $action->{relname} | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | . q{ - } | |||||||||||||||||||||||||||||||||||||||||
| 231 | . $ftp->message | ||||||||||||||||||||||||||||||||||||||||||
| 232 | . qq{\n} | ||||||||||||||||||||||||||||||||||||||||||
| 233 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # if we didn't have any errors, upload the digest | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if (not $errors) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | # verbose ouput | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | warn ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | q{PUT } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | . q{digest.md5} | ||||||||||||||||||||||||||||||||||||||||||
| 245 | . qq{\n} | ||||||||||||||||||||||||||||||||||||||||||
| 246 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 247 | if ($self->get_config->verbose(1)); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # upload the digest file | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $ftp->put('digest.md5'); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | warn qq{$errors error(s), digest file not transferred\n}; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | sub fetch_remote_digest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_remote_digest: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($fh, $filename, $get_ok); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # a temporary file to use | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ($fh, $filename) = tempfile(); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $config->{tmp_remote_digest} = $filename; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # get the (remote) digest file | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $get_ok = $self->get_ftp_client->get( | |||||||||||||||||||||||||||||||||||||||||
| 267 | file( | ||||||||||||||||||||||||||||||||||||||||||
| 268 | $self->get_ftp_root(), | ||||||||||||||||||||||||||||||||||||||||||
| 269 | q{digest.md5} | ||||||||||||||||||||||||||||||||||||||||||
| 270 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 271 | $filename | ||||||||||||||||||||||||||||||||||||||||||
| 272 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if (not $get_ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | warn "No remote digest\n"; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $self->set_remote_digest($filename); | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub ftp_sync { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ftp_sync: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my (@md5strings, $transfer_actions); | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # make sure we have an ftp client to use | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if (not defined $self->get_ftp_client) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | warn(qq{Failed to obtain remote FTP connection. Aborting upload.\n}); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # regenerate (local) md5s | ||||||||||||||||||||||||||||||||||||||||||
| 295 | find( | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $self->local_ftp_wanted(\@md5strings); | |||||||||||||||||||||||||||||||||||||||||
| 298 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | $config->{output_dir} | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | write_file( | |||||||||||||||||||||||||||||||||||||||||
| 302 | qq{$config->{output_dir}/digest.md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | @md5strings | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | # get the remote digest | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $self->fetch_remote_digest; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | # work out what needs to happen | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $transfer_actions = $self->build_transfer_actions; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | # do the remote update | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $self->do_remote_update($transfer_actions); | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | sub local_ftp_wanted { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
local_ftp_wanted: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my ($self, $md5string_list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
-f $_ and $_ ne "digest.md5" and not $_ =~ /\.sw?/
-f $_ and $_ ne "digest.md5"
MC/DC0%0/3
-f $_ and $_ ne "digest.md5" and not $_ =~ /\.sw?/
-f $_
$_ ne "digest.md5"
not $_ =~ /\.sw?/
Truth table0%0/4
A and B and not(C)
A= -f $_B= $_ ne "digest.md5"C= not $_ =~ /\.sw?/
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | -f $_ | ||||||||||||||||||||||||||||||||||||||||||
| 324 | and | ||||||||||||||||||||||||||||||||||||||||||
| 325 | $_ ne q{digest.md5} | ||||||||||||||||||||||||||||||||||||||||||
| 326 | and | ||||||||||||||||||||||||||||||||||||||||||
| 327 | $_ !~ m{\.sw?} | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | push @{$md5string_list}, | |||||||||||||||||||||||||||||||||||||||||
| 330 | $self->md5file($File::Find::name) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | . qq{\n}; | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub md5file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
md5file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $dir_prefix = $config->{output_dir}; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ($filedata, $md5sum, $rel_filename, $md5data); | |||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | # slurp the file | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | $filedata = read_file($file) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | or die "$file: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # get the md5sum of the file | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $md5sum = md5_hex($filedata); | |||||||||||||||||||||||||||||||||||||||||
| 346 | # trim off any leading directories - making filename relative) | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (defined $dir_prefix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $rel_filename = $file; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $rel_filename =~ s{\A${dir_prefix}/}{}; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | # return an md5 string | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return "$md5sum $rel_filename"; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub parse_md5file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_md5file: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my (%md5_of, @lines); | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if (not defined $file or $file =~ m{\A\s*\z}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $file or $file =~ /\A\s*\z/
MC/DC0%0/2
not defined $file or $file =~ /\A\s*\z/
not defined $file
$file =~ /\A\s*\z/
Truth table0%0/3
not(A) or B
A= not defined $fileB= $file =~ /\A\s*\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | # empty digest file | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | carp "undefined filename passed to parse_md5file()" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | if ($self->get_config->verbose(2)); | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if (! -f $file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | carp "$file: file not found" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | if ($self->get_config->verbose(2)); | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | # read in the file - ".q{}" forces any Path::Class objects to be | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # stringified | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | @lines = read_file($file.q{}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | or die "$file: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | # parse/split each line | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | foreach my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | chomp($line); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ($line =~ m{\A([a-z0-9]{32})\s+(.+)\z}xms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $md5_of{$2} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return \%md5_of; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | sub prepare_ftp_client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_ftp_client: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my $config = $self->get_config->get_siteconfig(); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $cliopt = $self->get_config->get_options(); | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | # make sure we have some defaults | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | $config->{ftp}{hostname} ||= 'localhost'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"ftp"}{"hostname"} ||= "localhost"
MC/DC0%0/1
$config->{"ftp"}{"hostname"} ||= "localhost"
$config->{"ftp"}{"hostname"}
Truth table0%0/2
A
A= $config->{"ftp"}{"hostname"}
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | $config->{ftp}{passive} ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"ftp"}{"passive"} ||= 0
MC/DC0%0/1
$config->{"ftp"}{"passive"} ||= 0
$config->{"ftp"}{"passive"}
Truth table0%0/2
A
A= $config->{"ftp"}{"passive"}
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $config->{ftp}{username} ||= 'anonymous'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"ftp"}{"username"} ||= "anonymous"
MC/DC0%0/1
$config->{"ftp"}{"username"} ||= "anonymous"
$config->{"ftp"}{"username"}
Truth table0%0/2
A
A= $config->{"ftp"}{"username"}
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | $config->{ftp}{password} ||= 'coward'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"ftp"}{"password"} ||= "coward"
MC/DC0%0/1
$config->{"ftp"}{"password"} ||= "coward"
$config->{"ftp"}{"password"}
Truth table0%0/2
A
A= $config->{"ftp"}{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | # if we already have an FTP object, use it | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if (defined $self->get_ftp_client) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | warn qq{using existing FTP object\n} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | if ($self->get_config->verbose(3)); | ||||||||||||||||||||||||||||||||||||||||||
| 404 | # nothing to actually do | ||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # make sure we can chdir() to the local root | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if (not chdir($config->{output_dir})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | warn qq{could not chdir to: $config->{output_dir}\n}; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | warn qq{creating new FTP object\n} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | if ($self->get_config->verbose(3)); | ||||||||||||||||||||||||||||||||||||||||||
| 415 | my $ftp = Net::FTP->new( | ||||||||||||||||||||||||||||||||||||||||||
| 416 | $config->{ftp}{hostname}, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | Debug => ($cliopt->{'ftp-debug'} || 0), | ||||||||||||||||||||||||||||||||||||||||||
| 418 | Passive => $config->{ftp}{passive}, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cliopt->{'ftp-debug'} || 0
MC/DC0%0/1
$cliopt->{'ftp-debug'} || 0
$cliopt->{'ftp-debug'}
Truth table0%0/2
A
A= $cliopt->{'ftp-debug'}
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | # make sure we've got a usable FTP object | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if (not defined $ftp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | warn(qq{Failed to connect to server [$config->{ftp}{hostname}]: $!\n}); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 424 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 425 | # try to login | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if (not $ftp->login( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | $config->{ftp}{username}, | ||||||||||||||||||||||||||||||||||||||||||
| 428 | $config->{ftp}{password} | ||||||||||||||||||||||||||||||||||||||||||
| 429 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 430 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | warn(qq{Failed to login as $config->{ftp}{username}\n}); | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | # try to cwd, if required | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if (defined $config->{ftp}{path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (not $ftp->cwd( $config->{ftp}{path} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | warn(qq{Cannot change directory to $config->{ftp}{path}\n}); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | # use binary transfer mode | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if (not $ftp->binary()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | warn(qq{Failed to set binary mode\n}); | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | # set our FTP_ROOT based on where we are now | ||||||||||||||||||||||||||||||||||||||||||
| 448 | $self->set_ftp_root( | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $ftp->pwd() | |||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $self->set_ftp_client($ftp); | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | __END__ | ||||||||||||||||||||||||||||||||||||||||||