| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # $Id: FTP_MD5Sync.pm,v 1.5 2004/06/10 13:18:02 eserte Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Copyright (C) 2002 Online Office Berlin. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Copyright (C) 2002 Slaven Rezic. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # terms of the GNU General Public License, see the file COPYING. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # WWW: http://we-framework.sourceforge.net | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | #XXX better mapping mechanism! rdist? an existing perl module? | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | WE_Frontend::Publish::FTP_MD5Sync - publish with FTP using MD5 fingerprints | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | use WE_Frontend::Main2; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | use WEsiteinfo qw($c); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $c->staging->transport("ftp-md5sync"); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | $main->publish; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | or | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | use WE_Frontend::Main; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | use WEsiteinfo; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | $WEsiteinfo::livetransport = "ftp-md5sync"; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | $main->publish; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | package WE_Frontend::Publish::FTP_MD5Sync; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | package WE_Frontend::Main; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | use Digest::MD5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | use WE_Frontend::Publish; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ($] < 5.006) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $INC{"warnings.pm"}++; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | eval q{ | |||||||||||||||||||||||||||||||||||||||||
| 60 | package warnings; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | sub unimport { } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | }; die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | use WE::Util::Functions qw(_save_pwd); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub publish_ftp_md5sync { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publish_ftp_md5sync: not called CC=56 SCAR=80.6
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $v = delete $args{-verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $dryrun = delete $args{-n}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $liveuser = $self->Config->staging->user; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $livepassword = $self->Config->staging->password; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $livedirectory = $self->Config->staging->directory; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $livecgidirectory = $self->Config->staging->cgidirectory; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $livehost = $self->Config->staging->host; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $pubhtmldir = $self->Config->paths->pubhtmldir; | |||||||||||||||||||||||||||||||||||||||||
| 83 | my @extracgi = (ref $self->Config->project->stagingextracgi eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | ? @{ $self->Config->project->stagingextracgi } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $md5listcgi = $self->Config->staging->stagingext->{'md5listcgi'}; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $topdirectory = $self->Config->staging->stagingext->{'topdirectory'}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $deleteold = $self->Config->staging->stagingext->{'deleteold'}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $movetotrash = $self->Config->staging->stagingext->{'movetotrash'}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $trashdirectory = $self->Config->staging->stagingext->{'trashdirectory'}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($self->Config->staging->stagingext->{'dryrun'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $dryrun++; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | die "Can't use deleteold and movetotrash" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$deleteold and $movetotrash
MC/DC0%0/2
$deleteold and $movetotrash
$deleteold
$movetotrash
Truth table0%0/3
A and B
A= $deleteoldB= $movetotrash
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | if $deleteold && $movetotrash; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | die "movetotrash defined but there is no trashdirectory" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$movetotrash and not defined $trashdirectory
MC/DC0%0/2
$movetotrash and not defined $trashdirectory
$movetotrash
not defined $trashdirectory
Truth table0%0/3
A and not(B)
A= $movetotrashB= not defined $trashdirectory
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | if $movetotrash && !defined $trashdirectory; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =head2 WESITEINFO CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | This refers to the old format (first name) or the new format (second | ||||||||||||||||||||||||||||||||||||||||||
| 104 | name). | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =item $livetransport or $c->staging->transport | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | The transport protocol should be set to "ftp-md5sync". | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =item $liveuser or $c->staging->user | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | The remote FTP user. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (!defined $liveuser || $liveuser eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $liveuser or $liveuser eq ""
MC/DC0%0/2
not defined $liveuser or $liveuser eq ""
not defined $liveuser
$liveuser eq ""
Truth table0%0/3
not(A) or B
A= not defined $liveuserB= $liveuser eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | die "The FTP user is missing (config member WEsiteinfo->staging->user)"; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =item $livepassword or $c->staging->password | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | The remote FTP password. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if (!defined $livepassword || $livepassword eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $livepassword or $livepassword eq ""
MC/DC0%0/2
not defined $livepassword or $livepassword eq ""
not defined $livepassword
$livepassword eq ""
Truth table0%0/3
not(A) or B
A= not defined $livepasswordB= $livepassword eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | die "The FTP password is missing (config member WEsiteinfo->staging->password)"; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =item $livedirectory or $c->staging->directory | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | The remote FTP directory. This is not the real filesystem path on the | ||||||||||||||||||||||||||||||||||||||||||
| 135 | remote host, but the virtual FTP path. For example: the real | ||||||||||||||||||||||||||||||||||||||||||
| 136 | filesystem path may be somthing like C</home/users/company>, but if | ||||||||||||||||||||||||||||||||||||||||||
| 137 | you login to the server as C<company>, you will see C</> as the FTP | ||||||||||||||||||||||||||||||||||||||||||
| 138 | root path. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | If the FTP root is C</>, the value of C<$livedirectory> should be an | ||||||||||||||||||||||||||||||||||||||||||
| 141 | empty string. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =item $livehost or $c->staging->host | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | The remove host. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (!defined $livehost || $livehost eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $livehost or $livehost eq ""
MC/DC0%0/2
not defined $livehost or $livehost eq ""
not defined $livehost
$livehost eq ""
Truth table0%0/3
not(A) or B
A= not defined $livehostB= $livehost eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | die "The target FTP host is missing (config member WEsiteinfo->staging->host)"; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =item $pubhtmldir or $c->paths->pubhtmldir | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | The local htdocs directory. | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if (!defined $pubhtmldir || $pubhtmldir eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $pubhtmldir or $pubhtmldir eq ""
MC/DC0%0/2
not defined $pubhtmldir or $pubhtmldir eq ""
not defined $pubhtmldir
$pubhtmldir eq ""
Truth table0%0/3
not(A) or B
A= not defined $pubhtmldirB= $pubhtmldir eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | die "The publish html directory is missing (config member WEsiteinfo->paths->pubhtmldir)"; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =item $livecgidirectory or $c->staging->cgidirectory | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | If there are CGI programs to be published, the remote cgi directory | ||||||||||||||||||||||||||||||||||||||||||
| 166 | have to be specified. The same rules as in C<$livedirectory> apply. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =item @stagingextracgi or $c->project->stagingextracgi | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | An array reference with additional cgi scripts to be published. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (@extracgi && (!defined $livecgidirectory || $livecgidirectory eq '')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
not defined $livecgidirectory or $livecgidirectory eq ""
MC/DC0%0/3
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
@extracgi
not defined $livecgidirectory
$livecgidirectory eq ""
Truth table0%0/4
A and not(B) or C
A= @extracgiB= not defined $livecgidirectoryC= $livecgidirectory eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | die "Extra CGI scripts are defined (@extracgi), | |||||||||||||||||||||||||||||||||||||||||
| 176 | but the WEsiteinfo->staging->cgidirectory config is missing"; | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | =item $livestagingext or $c->staging->stagingext | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | A hash reference with additional attributes: | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =item dryrun | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | If set to a true value, then do not execute the FTP commands, just | ||||||||||||||||||||||||||||||||||||||||||
| 188 | show them. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | =item md5listcgi | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | The remote CGI script to create the MD5 list. The script is included | ||||||||||||||||||||||||||||||||||||||||||
| 193 | in the C<WE_Framework> as C<cgi-scripts/get_md5_list.cgi>. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | =item topdirectory | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | The top directory of the remote server. Here the real filesystem path | ||||||||||||||||||||||||||||||||||||||||||
| 198 | should be used. In the example above, this would be | ||||||||||||||||||||||||||||||||||||||||||
| 199 | C</home/users/company>. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =item deleteold | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | If true, then outdated remote files (not existing on the local side) | ||||||||||||||||||||||||||||||||||||||||||
| 204 | are deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | =item movetotrash | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | If true, then outdated remote files will be moved to the | ||||||||||||||||||||||||||||||||||||||||||
| 209 | C<trashdirectory>. Cannot be used together with C<deleteold>. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | =item trashdirectory | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | The FTP directory name of a trash directory. Have to be defined if | ||||||||||||||||||||||||||||||||||||||||||
| 214 | C<movetotrash> is set. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | =head2 GETMD5LIST.CGI CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | The CGI script C<get_md5_list.cgi> is configured by creating a perl | ||||||||||||||||||||||||||||||||||||||||||
| 223 | file called C<get_md5_list.cgi.config> which should reside in the same | ||||||||||||||||||||||||||||||||||||||||||
| 224 | directory as the CGI script. The following perl variables may be set | ||||||||||||||||||||||||||||||||||||||||||
| 225 | as configuration variables: | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | =item @directories | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | A list of directories for which the MD5 fingerprints should be | ||||||||||||||||||||||||||||||||||||||||||
| 232 | collected. Normally these are C<livedirectory> and C<livecgidirectory> | ||||||||||||||||||||||||||||||||||||||||||
| 233 | from the C<WEsiteinfo> configuration. | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | =item @digest_method | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | Specify a list with the preferred methods to get the MD5 digest. This does not need to be set; C<get_md5_list.cgi> is smart enough to get a supported method automatically. Permitted values are: | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | =item 'perl:Digest::MD5' | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | Use the perl module L<Digest::MD5|Digest::MD5>. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | =item 'perl:MD5' | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | Use the (old) perl module L<MD5|MD5>. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =item 'cmd:md5' | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | Use the OS command C<md5> (BSD systems). | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | =item 'cmd:md5sum' | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | Use the OS command C<md5sum> (Linux and Solaris systems). | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | =item 'perl:Digest::Perl::MD5' | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | Use the pure perl module L<Digest::Perl::MD5|Digest::Perl::MD5>. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | =item 'cmd:cksum' | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | Use the obsolete C<chksum> command. | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | =item 'stat:modtime' | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | Just stat the file and use the modification time of the file. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | =item @exclude | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | A list of files to be excluded. The check will be done against the | ||||||||||||||||||||||||||||||||||||||||||
| 274 | partial filename, beginning at the paths as in C<@directories>. | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | =item %exclude | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | Per-directory (as in C<@directories>) exclude list. For example, if | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | @directories = ("/home/htdocs", "/home/htdocs/cgi-bin"); | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | is specified, then C<%exclude> may be | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | %exclude = ("/home/htdocs" => ['.htaccess', 'cgi-bin/.*'], | ||||||||||||||||||||||||||||||||||||||||||
| 285 | "/home/htdocs/cgi-bin" => ['mails.*']); | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | Note that it is generally problematic to have subdirs specified in | ||||||||||||||||||||||||||||||||||||||||||
| 288 | C<@directories> --- in such a case the C<%exclude> variable should be | ||||||||||||||||||||||||||||||||||||||||||
| 289 | set cleverly. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | =item $verbose | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | Be verbose if set to a true value. The messages are printed to STDERR. | ||||||||||||||||||||||||||||||||||||||||||
| 294 | Note that some servers do not like output to STDERR --- it will get | ||||||||||||||||||||||||||||||||||||||||||
| 295 | mixed up with STDOUT output. | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if (!defined $md5listcgi || $md5listcgi eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $md5listcgi or $md5listcgi eq ""
MC/DC0%0/2
not defined $md5listcgi or $md5listcgi eq ""
not defined $md5listcgi
$md5listcgi eq ""
Truth table0%0/3
not(A) or B
A= not defined $md5listcgiB= $md5listcgi eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | die "The CGI path to the md5list script is not defined"; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if (!defined $topdirectory) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | die "The topdirectory is missing (config member WEsiteinfo->staging->stagingext->{topdirectory})"; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ($v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | print <<EOF; | |||||||||||||||||||||||||||||||||||||||||
| 310 | Using FTP Protocol. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | FTP remote host: $livehost | ||||||||||||||||||||||||||||||||||||||||||
| 312 | FTP remote user: $liveuser | ||||||||||||||||||||||||||||||||||||||||||
| 313 | FTP remote directory: $livedirectory | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | @{[ @extracgi ? "FTP remote CGI directory: $livecgidirectory" : "" ]} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | md5list CGI: $md5listcgi | ||||||||||||||||||||||||||||||||||||||||||
| 316 | topdirectory: $topdirectory | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | @{[ $dryrun ? "Do not execute any create/update/delete actions, just show them" : "" ]} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ($deleteold) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | print "delete old files\n"; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } elsif ($movetotrash) { | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | print "move old files to trash directory: $trashdirectory\n"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | print "keep old files\n"; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $request = HTTP::Request->new('GET', $md5listcgi); | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $res = $ua->request($request); | |||||||||||||||||||||||||||||||||||||||||
| 331 | #my $res = $ua->get($md5listcgi); | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if (!$res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | print $res->error_as_HTML; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | die "Can't get MD5 list from $md5listcgi"; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my %md5list; | |||||||||||||||||||||||||||||||||||||||||
| 338 | my $curr_dir; | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | foreach my $line (split /\n/, $res->content) { | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ($line =~ /^\#\s*([^:]+):\s*(.*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my($key,$val) = ($1,$2); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($key =~ /^digest$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ($val !~ /md5/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | die "Sorry, only MD5 digest are supported now"; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | } elsif ($key =~ /^directory$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $curr_dir = $val; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # ignore | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if (!defined $curr_dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | die "Current directory is not defined ( $line )"; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my($file, $md5) = split /\t/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $md5list{$curr_dir}->{$file} = $md5; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | print "Got MD5 list from $md5listcgi:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | print Data::Dumper->Dumpxs([\%md5list],['md5list']), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | my $ftp = Net::FTP->new($livehost, Debug => 0) or die $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $ftp->login($liveuser, $livepassword) or die "Can't login with $liveuser"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $ftp->binary(); | |||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if (defined $livedirectory && $livedirectory ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $livedirectory and $livedirectory ne ""
MC/DC0%0/2
defined $livedirectory and $livedirectory ne ""
defined $livedirectory
$livedirectory ne ""
Truth table0%0/3
A and B
A= defined $livedirectoryB= $livedirectory ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $ftp->cwd($livedirectory) or die "Can't remote chdir to $livedirectory"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ($dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | print "Execute chdir $livedirectory, now in directory: " . $ftp->pwd . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $pub_files = WE_Frontend::Publish::get_files_to_publish($self, %args); | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my @directories = @{ $pub_files->{Directories} }; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my @files = @{ $pub_files->{Files} }; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my @published_files; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | my $remotedir = ($topdirectory ne "" ? "$topdirectory/" : "") . $livedirectory; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $remotedir =~ s|/+|/|g; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | # Ack! This will fetch all local files and directories, regardless | ||||||||||||||||||||||||||||||||||||||||||
| 385 | # whether it is new or old | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my %args2 = %args; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | delete $args2{-since}; # get really all! | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $pub_files = WE_Frontend::Publish::get_files_to_publish($self, %args2); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my %local_files = map { ("$remotedir/$_" => 1) } @{ $pub_files->{Files} }; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my @files_to_delete; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | foreach my $dir (keys %md5list) { | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | foreach my $file (keys %{$md5list{$dir}}) { | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if (!exists $local_files{"$dir/$file"}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | (my $remotefile = "$dir/$file") =~ s|^\Q$remotedir\E/?||; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | push @files_to_delete, $remotefile; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | _save_pwd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | chdir $pubhtmldir || die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # XXX only create directories if really necessary! | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | foreach my $dir (@directories) { | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if ($v) { print "Create folder $dir\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if (!$dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $ftp->mkdir($dir); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | print "Execute mkdir $dir\n"; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if (!-r $file) { warn "The local file $pubhtmldir/$file is not readable" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $message = "Create document $remotedir | $file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $copy = 1; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if (exists $md5list{$remotedir}->{$file}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $md5 = Digest::MD5->new; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | open(F, $file) or die "Can't read file $file: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $md5->addfile(\*F); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | close F; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $local_md5 = $md5->hexdigest; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if ($local_md5 eq $md5list{$remotedir}->{$file}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $copy = 0; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if ($v) { print "skipping document $file\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $message = "Update document $file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if ($copy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | if ($v) { print $message } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if (!$dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $ftp->put($file, $file) or warn "Can't put $pubhtmldir/$file to remote host $livehost"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | print "Execute put $file to $file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | push @published_files, $file; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | # see, which files are left to delete. | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my @deleted_on_remote; | |||||||||||||||||||||||||||||||||||||||||
| 448 | my @moved_to_trash_on_remote; | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if ($deleteold) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | foreach my $file (@files_to_delete) { | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | if ($v) { print "deleting remote file $file\n"; }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if (!$dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $ftp->delete($file) or warn "Can't delete $pubhtmldir/$file on remote host $livehost\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | print "Execute delete $file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | push @deleted_on_remote, $file; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } elsif ($movetotrash) { | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | require File::Basename; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | foreach my $file (@files_to_delete) { | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ($v) { print "move remote file $file to $trashdirectory\n"; }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my $basefile = File::Basename::basename($file); | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if (!$dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | $ftp->rename($file, "$trashdirectory/$basefile") or warn "Can't rename $file to $trashdirectory/$basefile on remote host $livehost\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | print "Execute rename $file to $trashdirectory/$basefile\n"; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | push @moved_to_trash_on_remote, $file; | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | ▶ | } elsif (@files_to_delete && $v) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
@files_to_delete and $v
MC/DC0%0/2
@files_to_delete and $v
@files_to_delete
$v
Truth table0%0/3
A and B
A= @files_to_deleteB= $v
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | print "The following files are outdated on the remote:\n", | |||||||||||||||||||||||||||||||||||||||||
| 473 | join(", ", @files_to_delete), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $ret = {Directories => \@directories, | |||||||||||||||||||||||||||||||||||||||||
| 477 | Files => \@files, | ||||||||||||||||||||||||||||||||||||||||||
| 478 | PublishedFiles => \@published_files, | ||||||||||||||||||||||||||||||||||||||||||
| 479 | DeletedOnRemote => \@deleted_on_remote, | ||||||||||||||||||||||||||||||||||||||||||
| 480 | MovedToTrashOnRemote => \@moved_to_trash_on_remote, | ||||||||||||||||||||||||||||||||||||||||||
| 481 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | __END__ | ||||||||||||||||||||||||||||||||||||||||||