diff --git a/lib/WebGUI/Session/Id.pm b/lib/WebGUI/Session/Id.pm index 4737f2c80..950fd64c2 100644 --- a/lib/WebGUI/Session/Id.pm +++ b/lib/WebGUI/Session/Id.pm @@ -42,6 +42,18 @@ These methods are available from this class: =cut +#------------------------------------------------------------------- + +=head2 DESTROY ( ) + +Deconstructor. + +=cut + +sub DESTROY { + my $self = shift; + undef $self; +} #------------------------------------------------------------------- @@ -56,28 +68,14 @@ Hex value to convert to guid. =cut sub fromHex { - my $self = shift; + my $self = shift; my $hexId = shift; - my $binId = pack('H2' x 16, unpack('A2' x 16, $hexId)); - my $id = substr(encode_base64($binId), 0, 22); + my $binId = pack( 'H2' x 16, unpack( 'A2' x 16, $hexId ) ); + my $id = substr( encode_base64($binId), 0, 22 ); $id =~ tr{+/}{_-}; return $id; } -#------------------------------------------------------------------- - -=head2 DESTROY ( ) - -Deconstructor. - -=cut - -sub DESTROY { - my $self = shift; - undef $self; -} - - #------------------------------------------------------------------- =head2 getValidator diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index 000001bc2..bcc41be1e 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -142,25 +142,28 @@ consecutive slashes in the path part of the URL will be replaced with a single s =cut sub extras { - my $self = shift; - my $path = shift; - my $url = $self->session->config->get("extrasURL"); + my $self = shift; + my $path = shift; + my $url = $self->session->config->get("extrasURL"); my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'}) { - unless ($path and grep $path =~ m/$_/, @{$cdnCfg->{'extrasExclude'}}) { - if ($cdnCfg->{'extrasSsl'} and - ($self->session->env->get('HTTPS') eq 'on' or - $self->session->env->get('SSLPROXY'))) { - $url = $cdnCfg->{'extrasSsl'}; - } else { - $url = $cdnCfg->{'extrasCdn'}; - } - } # if excluded, stick with regular extrasURL + if ( $cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'} ) { + unless ( $path and grep $path =~ m/$_/, @{ $cdnCfg->{'extrasExclude'} } ) { + if ($cdnCfg->{'extrasSsl'} + and ( $self->session->env->get('HTTPS') eq 'on' + or $self->session->env->get('SSLPROXY') ) + ) + { + $url = $cdnCfg->{'extrasSsl'}; + } + else { + $url = $cdnCfg->{'extrasCdn'}; + } + } # if excluded, stick with regular extrasURL } $url .= '/' . $path; - $url =~ s$(?session->errorHandler->error($errorMessage); } - #------------------------------------------------------------------- =head2 _cdnAdd ( ) @@ -117,23 +116,24 @@ NOTE: This is a private method and should never be called except internally to t =cut sub _cdnAdd { - my $self = shift; - my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'}) { - if ($cdnCfg->{'queuePath'}) { - my $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex($self->getId); - my $dest; - if ( open $dest, '>', $cdnFile ) { - close $dest; # created empty file - } else { - $self->_addError("CDN: Couldn't open file $cdnFile for writing due to error: ".$!); - } - } else { - $self->_addError('Invalid CDN configuration - missing queuePath'); - } - } -} - + my $self = shift; + my $cdnCfg = $self->session->config->get('cdn'); + if ( $cdnCfg and $cdnCfg->{'enabled'} ) { + if ( $cdnCfg->{'queuePath'} ) { + my $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex( $self->getId ); + my $dest; + if ( open $dest, '>', $cdnFile ) { + close $dest; # created empty file + } + else { + $self->_addError( "CDN: Couldn't open file $cdnFile for writing due to error: " . $! ); + } + } + else { + $self->_addError('Invalid CDN configuration - missing queuePath'); + } + } +} ## end sub _cdnAdd #------------------------------------------------------------------- @@ -150,30 +150,31 @@ Delete the ".cdn" file - clear vs. delete. =cut sub _cdnDel { - my $self = shift; - my $delDotCdn = shift; - my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'}) { - my $cdnFile; # path/name of flag and/or queue file - if ($delDotCdn) { - $cdnFile = $self->getPath . '/.cdn'; - unlink $cdnFile; - } - if ($cdnCfg->{'queuePath'}) { - $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex($self->getId); - my $dest; - if ( open $dest, '>', $cdnFile ) { - print $dest "deleted\n"; - close $dest; - } else { - $self->_addError("Couldn't open file $cdnFile for writing due to error: ".$!); - } - } else { - $self->_addError('Invalid CDN configuration - missing queuePath'); - } - } -} - + my $self = shift; + my $delDotCdn = shift; + my $cdnCfg = $self->session->config->get('cdn'); + if ( $cdnCfg and $cdnCfg->{'enabled'} ) { + my $cdnFile; # path/name of flag and/or queue file + if ($delDotCdn) { + $cdnFile = $self->getPath . '/.cdn'; + unlink $cdnFile; + } + if ( $cdnCfg->{'queuePath'} ) { + $cdnFile = $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex( $self->getId ); + my $dest; + if ( open $dest, '>', $cdnFile ) { + print $dest "deleted\n"; + close $dest; + } + else { + $self->_addError( "Couldn't open file $cdnFile for writing due to error: " . $! ); + } + } + else { + $self->_addError('Invalid CDN configuration - missing queuePath'); + } + } ## end if ( $cdnCfg and $cdnCfg... +} ## end sub _cdnDel #------------------------------------------------------------------- @@ -363,7 +364,7 @@ sub addFileFromFormPost { my $attachmentCount = 1; foreach my $upload ($session->request->upload($formVariableName)) { $session->errorHandler->info("Trying to get " . $upload->filename." from ".$formVariableName); - if ($attachmentCount > $attachmentLimit) { + if ( $attachmentCount > $attachmentLimit ) { $self->_cdnAdd; return $filename; } @@ -685,24 +686,26 @@ Also delete the related file in config/cdn/queuePath. sub deleteFromCdn { my $self = shift; my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'} - and $cdnCfg->{'syncProgram'}) { - my $id = $self->session->id->toHex($self->getId); - my $cmd = sprintf($cdnCfg->{'deleteProgram'}, $id); - if ($cmd =~ /$id/) { # sanity check, no rm -rf / - system($cmd); - if ($?) { # This may occur benign in the case delete after clear - $self->_addError("Error running CDN deleteProgram: $?"); - } - if ($cdnCfg->{'queuePath'}) { - unlink $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex($self->getId); - } - } else { # Presume configuration error, missing %s - $self->_addError("CDN deleteProgram: storage ID missing from command: $cmd"); - } - } -} - + if ( $cdnCfg + and $cdnCfg->{'enabled'} + and $cdnCfg->{'syncProgram'} ) + { + my $id = $self->session->id->toHex( $self->getId ); + my $cmd = sprintf( $cdnCfg->{'deleteProgram'}, $id ); + if ( $cmd =~ /$id/ ) { # sanity check, no rm -rf / + system($cmd); + if ($?) { # This may occur benign in the case delete after clear + $self->_addError("Error running CDN deleteProgram: $?"); + } + if ( $cdnCfg->{'queuePath'} ) { + unlink $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex( $self->getId ); + } + } + else { # Presume configuration error, missing %s + $self->_addError("CDN deleteProgram: storage ID missing from command: $cmd"); + } + } ## end if ( $cdnCfg and $cdnCfg... +} ## end sub deleteFromCdn #------------------------------------------------------------------- @@ -814,30 +817,30 @@ A reference to the current session. =cut sub getCdnFileIterator { - my $class = shift; - my $session = shift; - my $cdnCfg = $session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'}) { - if ($cdnCfg->{'queuePath'}) { - if (opendir my $DH, $cdnCfg->{'queuePath'}) { - my @ids = grep { !/^\.+$/ } - readdir($DH); - close $DH; - my $sub = sub { - my $id = shift @ids; - return if !$id; - return $class->get($session, $session->id->fromHex($id)); - }; - return $sub; - } else { - $session->errorHandler->warn("CDN: cannot read directory $cdnCfg->{'queuePath'}"); - } - } else { - $session->errorHandler->warn("CDN: enabled but no queuePath"); - } - } -} - + my $class = shift; + my $session = shift; + my $cdnCfg = $session->config->get('cdn'); + if ( $cdnCfg and $cdnCfg->{'enabled'} ) { + if ( $cdnCfg->{'queuePath'} ) { + if ( opendir my $DH, $cdnCfg->{'queuePath'} ) { + my @ids = grep { !/^\.+$/ } readdir($DH); + close $DH; + my $sub = sub { + my $id = shift @ids; + return if !$id; + return $class->get( $session, $session->id->fromHex($id) ); + }; + return $sub; + } + else { + $session->errorHandler->warn("CDN: cannot read directory $cdnCfg->{'queuePath'}"); + } + } + else { + $session->errorHandler->warn("CDN: enabled but no queuePath"); + } + } ## end if ( $cdnCfg and $cdnCfg... +} ## end sub getCdnFileIterator #------------------------------------------------------------------- @@ -1185,34 +1188,36 @@ If specified, we'll return a URL to the file rather than the storage location. =cut sub getUrl { - my $self = shift; - my $file = shift; - my $url = $self->session->config->get("uploadsURL") - . '/' - . $self->getPathFrag; - my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'url'} - and -e $self->getPath . '/.cdn') { - my $sep = '/'; # separator, if not already present trailing - if ($cdnCfg->{'sslAlt'} and - ($self->session->env->get('HTTPS') eq 'on' or - $self->session->env->get('SSLPROXY'))) { - if ($cdnCfg->{'sslUrl'}) { - substr($cdnCfg->{'sslUrl'}, -1) eq '/' and $sep = ''; - $url = $cdnCfg->{'sslUrl'} . $sep . $self->session->id->toHex($self->getId); - } # else do NOT override $url with CDN URL ($url = $sslUrl || $url) - } else { - substr($cdnCfg->{'url'}, -1) eq '/' and $sep = ''; - $url = $cdnCfg->{'url'} . $sep . $self->session->id->toHex($self->getId); - } - } - if (defined $file) { - $url .= '/'.$file; - } - return $url; -} - - + my $self = shift; + my $file = shift; + my $url = $self->session->config->get("uploadsURL") . '/' . $self->getPathFrag; + my $cdnCfg = $self->session->config->get('cdn'); + if ( $cdnCfg + and $cdnCfg->{'enabled'} + and $cdnCfg->{'url'} + and -e $self->getPath . '/.cdn' ) + { + my $sep = '/'; # separator, if not already present trailing + if ($cdnCfg->{'sslAlt'} + and ( $self->session->env->get('HTTPS') eq 'on' + or $self->session->env->get('SSLPROXY') ) + ) + { + if ( $cdnCfg->{'sslUrl'} ) { + substr( $cdnCfg->{'sslUrl'}, -1 ) eq '/' and $sep = ''; + $url = $cdnCfg->{'sslUrl'} . $sep . $self->session->id->toHex( $self->getId ); + } # else do NOT override $url with CDN URL ($url = $sslUrl || $url) + } + else { + substr( $cdnCfg->{'url'}, -1 ) eq '/' and $sep = ''; + $url = $cdnCfg->{'url'} . $sep . $self->session->id->toHex( $self->getId ); + } + } ## end if ( $cdnCfg and $cdnCfg... + if ( defined $file ) { + $url .= '/' . $file; + } + return $url; +} ## end sub getUrl #------------------------------------------------------------------- @@ -1602,29 +1607,32 @@ the related file in config/cdn/queuePath. sub syncToCdn { my $self = shift; my $cdnCfg = $self->session->config->get('cdn'); - if ($cdnCfg and $cdnCfg->{'enabled'} - and $cdnCfg->{'syncProgram'}) { - my $originalDir = Cwd::cwd(); - my $locDir = join '/', $self->session->config->get('uploadsPath'), @{$self->{_pathParts}}[0..1]; - chdir $locDir or croak 'Unable to chdir to ' . $locDir . " : $!"; - my $cmd = sprintf($cdnCfg->{'syncProgram'}, $self->session->id->toHex($self->getId)); - system($cmd); - if ($?) { - $self->_addError("Error running CDN syncProgram: $?"); - } elsif ($cdnCfg->{'queuePath'}) { - unlink $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex($self->getId); - } - chdir $originalDir; - my $dest; - my $cdnFile = $self->getPath . '/.cdn'; - if ( open $dest, '>', $cdnFile ) { - close $dest; # created empty file - } else { - $self->_addError("Couldn't open file $cdnFile for writing due to error: ".$!); - } - } -} - + if ( $cdnCfg + and $cdnCfg->{'enabled'} + and $cdnCfg->{'syncProgram'} ) + { + my $originalDir = Cwd::cwd(); + my $locDir = join '/', $self->session->config->get('uploadsPath'), @{ $self->{_pathParts} }[ 0 .. 1 ]; + chdir $locDir or croak 'Unable to chdir to ' . $locDir . " : $!"; + my $cmd = sprintf( $cdnCfg->{'syncProgram'}, $self->session->id->toHex( $self->getId ) ); + system($cmd); + if ($?) { + $self->_addError("Error running CDN syncProgram: $?"); + } + elsif ( $cdnCfg->{'queuePath'} ) { + unlink $cdnCfg->{'queuePath'} . '/' . $self->session->id->toHex( $self->getId ); + } + chdir $originalDir; + my $dest; + my $cdnFile = $self->getPath . '/.cdn'; + if ( open $dest, '>', $cdnFile ) { + close $dest; # created empty file + } + else { + $self->_addError( "Couldn't open file $cdnFile for writing due to error: " . $! ); + } + } ## end if ( $cdnCfg and $cdnCfg... +} ## end sub syncToCdn #------------------------------------------------------------------- diff --git a/sbin/syncToCdn.pl b/sbin/syncToCdn.pl index 7e5cc2911..980246dba 100644 --- a/sbin/syncToCdn.pl +++ b/sbin/syncToCdn.pl @@ -10,9 +10,9 @@ our $webguiRoot; -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); +BEGIN { + $webguiRoot = ".."; + unshift( @INC, $webguiRoot . "/lib" ); } use strict; @@ -28,31 +28,30 @@ my $override; my $quiet; GetOptions( - 'configFile=s' => \$configFile, - 'override' => \$override, - 'migrate' => \$migrate, - 'quiet' => \$quiet, + 'configFile=s' => \$configFile, + 'override' => \$override, + 'migrate' => \$migrate, + 'quiet' => \$quiet, ); - -if ($configFile eq "") { - printHelp(); - exit 4; -}; +if ( $configFile eq "" ) { + printHelp(); + exit 4; +} if ($help) { - printHelp(); - exit 2; + printHelp(); + exit 2; } # don't want two copies of this to run simultaneously -unless (flock(DATA, LOCK_EX|LOCK_NB)) { +unless ( flock( DATA, LOCK_EX | LOCK_NB ) ) { print "$0 is already running. Exiting.\n"; exit 3; } sub printHelp { - print < @@ -97,29 +96,30 @@ EXIT STATUS Content Delivery Network (CDN) is not enabled. STOP -} +} ## end sub printHelp -if (!($^O =~ /^Win/i) && $> != 0 && !$override) { - print "You must be the super user to use this utility.\n"; - exit 1; +if ( !( $^O =~ /^Win/i ) && $> != 0 && !$override ) { + print "You must be the super user to use this utility.\n"; + exit 1; } print "Starting..." unless ($quiet); -my $session = WebGUI::Session->open($webguiRoot,$configFile); -$session->user({userId=>3}); +my $session = WebGUI::Session->open( $webguiRoot, $configFile ); +$session->user( { userId => 3 } ); print "OK\n" unless ($quiet); my $cdnCfg = $session->config->get('cdn'); -unless ($cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'queuePath'}) { - print "Content delivery network (CDN) is not enabled in $configFile.\n"; - exit 5; +unless ( $cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'queuePath'} ) { + print "Content delivery network (CDN) is not enabled in $configFile.\n"; + exit 5; } # Here is the core of the script -if ($migrate) { - syncUploads($session); -} else { - syncQueue($session, $cdnCfg); +if ($migrate) { + syncUploads($session); +} +else { + syncQueue( $session, $cdnCfg ); } print "Cleaning up..." unless ($quiet); @@ -129,77 +129,81 @@ $session->close(); print "OK\n" unless ($quiet); exit 0; - #----------------------------------------- # syncQueue(session, cdnConfig) #----------------------------------------- -sub syncQueue { +sub syncQueue { my $session = shift; - my $cdnCfg = shift; + my $cdnCfg = shift; my $locIter = WebGUI::Storage->getCdnFileIterator($session); - while (my $store = $locIter->()) { - my $ctrlFile = $cdnCfg->{'queuePath'} . '/' . $session->id->toHex($store->getId); - if (-r $ctrlFile and -s $ctrlFile < 12) { - if (! -s $ctrlFile) { # Empty means sync/add/update - $store->syncToCdn; - } else { # expect "deleted" but be careful. - if (open my $ctrlFH, "<$ctrlFile") { - my $directive = <$ctrlFH>; - chomp $directive; - close $ctrlFH; - if ($directive =~ m/^deleted$/i) { - $store->deleteFromCdn; - } # else unknown - ignore - } else { - warn "Cannot read CDN control file $ctrlFile."; - $session->errorHandler->warn("Cannot read CDN control file $ctrlFile."); - } - } - } else { # missing or invalid - print "No recognizable CDN control file $ctrlFile.\n"; - } - } -} # end syncQueue - + while ( my $store = $locIter->() ) { + my $ctrlFile = $cdnCfg->{'queuePath'} . '/' . $session->id->toHex( $store->getId ); + if ( -r $ctrlFile and -s $ctrlFile < 12 ) { + if ( !-s $ctrlFile ) { # Empty means sync/add/update + $store->syncToCdn; + } + else { # expect "deleted" but be careful. + if ( open my $ctrlFH, "<$ctrlFile" ) { + my $directive = <$ctrlFH>; + chomp $directive; + close $ctrlFH; + if ( $directive =~ m/^deleted$/i ) { + $store->deleteFromCdn; + } # else unknown - ignore + } + else { + warn "Cannot read CDN control file $ctrlFile."; + $session->errorHandler->warn("Cannot read CDN control file $ctrlFile."); + } + } + } ## end if ( -r $ctrlFile and ... + else { # missing or invalid + warn "No recognizable CDN control file $ctrlFile."; + $session->errorHandler->warn("No recognizable CDN control file $ctrlFile."); + } + } ## end while ( my $store = $locIter... +} # end syncQueue #----------------------------------------- # syncUploads(session) #----------------------------------------- -sub syncUploads { +sub syncUploads { my $session = shift; + # Alternate approach would be touch queue files, then run queue. my $uDir = $session->config->get('uploadsPath'); - if (opendir my $DH, $uDir) { - my @part1 = grep { !/^\.+$/ } readdir($DH); - foreach my $subdir (@part1) { - if (opendir my $SD, "$uDir/$subdir") { - my @part2 = grep { !/^\.+$/ } readdir($SD); - foreach my $sub2 (@part2) { - if (opendir my $S2, "$uDir/$subdir/$sub2") { - my @fileId = grep { !/^\.+$/ } readdir($S2); - foreach my $fileId (@fileId) { - my $store = WebGUI::Storage->get($session, - $session->id->fromHex($fileId)); - $store->syncToCdn; # here is the meat - } - close $S2; - } else { - $session->errorHandler->warn("Unable to open $sub2 for directory reading"); + if ( opendir my $DH, $uDir ) { + my @part1 = grep { !/^\.+$/ } readdir($DH); + foreach my $subdir (@part1) { + if ( opendir my $SD, "$uDir/$subdir" ) { + my @part2 = grep { !/^\.+$/ } readdir($SD); + foreach my $sub2 (@part2) { + if ( opendir my $S2, "$uDir/$subdir/$sub2" ) { + my @fileId = grep { !/^\.+$/ } readdir($S2); + foreach my $fileId (@fileId) { + my $store = WebGUI::Storage->get( $session, $session->id->fromHex($fileId) ); + $store->syncToCdn; # here is the meat + } + close $S2; + } + else { + $session->errorHandler->warn("Unable to open $sub2 for directory reading"); + } } - } - close $SD; - } else { - $session->errorHandler->warn("Unable to open $subdir for directory reading"); - } - } - close $DH; - } else { - $session->errorHandler->warn("Unable to open $uDir for directory reading"); + close $SD; + } ## end if ( opendir my $SD, "$uDir/$subdir") + else { + $session->errorHandler->warn("Unable to open $subdir for directory reading"); + } + } ## end foreach my $subdir (@part1) + close $DH; + } ## end if ( opendir my $DH, $uDir) + else { + $session->errorHandler->warn("Unable to open $uDir for directory reading"); } -} # end syncUploads - +} # end syncUploads __DATA__ This exists so flock() code above works. diff --git a/t/Session/Url.t b/t/Session/Url.t index 6624aa9f6..c1145a434 100644 --- a/t/Session/Url.t +++ b/t/Session/Url.t @@ -286,7 +286,7 @@ my $extras = $origExtras; my $savecdn = $session->config->get('cdn'); if ($savecdn) { - $session->config->delete('cdn'); + $session->config->delete('cdn'); } # Note: the CDN configuration will be reverted in the END @@ -310,11 +310,11 @@ is($session->url->extras('/dir1//foo.html'), join('', $extras,'dir1/foo.html'), $extras = 'http://mydomain.com/'; $session->config->set('extrasURL', $extras); -my $cdnCfg = { "enabled" => 1, - "extrasCdn" => "http://extras.example.com/", - "extrasSsl" => "https://ssl.example.com/", - "extrasExclude" => ["^tiny"] - }; +my $cdnCfg = { "enabled" => 1, + "extrasCdn" => "http://extras.example.com/", + "extrasSsl" => "https://ssl.example.com/", + "extrasExclude" => ["^tiny"] + }; $session->config->set('cdn', $cdnCfg); is($session->url->extras('/dir1/foo.html'), join('', $cdnCfg->{extrasCdn}, 'dir1/foo.html'), 'extras cleartext with CDN'); diff --git a/t/Storage.t b/t/Storage.t index cf4cd10b5..e57659ac6 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -75,7 +75,7 @@ is( $storage1->getPathFrag, '7e/8a/7e8a1b6a', 'pathFrag returns correct value'); my $savecdn = $session->config->get('cdn'); if ($savecdn) { - $session->config->delete('cdn'); + $session->config->delete('cdn'); } # Note: the CDN configuration will be reverted after CDN tests below @@ -381,12 +381,13 @@ foreach my $iconTest (@{ $fileIconTests }) { # #################################################### -my $cdnCfg = { "enabled" => 1, - "url" => "file:///data/storage", - "queuePath" => "/data/cdnqueue", - "syncProgram" => "cp -r -- '%s' /data/storage/", - "deleteProgram" => "rm -r -- '/data/storage/%s' > /dev/null 2>&1" - }; +my $cdnCfg = { + "enabled" => 1, + "url" => "file:///data/storage", + "queuePath" => "/data/cdnqueue", + "syncProgram" => "cp -r -- '%s' /data/storage/", + "deleteProgram" => "rm -r -- '/data/storage/%s' > /dev/null 2>&1" +}; my ($addedCdnQ, $addedCdnU); $addedCdnQ = mkdir $cdnCfg->{'queuePath'} unless -e $cdnCfg->{'queuePath'}; my $dest = substr($cdnCfg->{'url'}, 7); @@ -415,23 +416,21 @@ my $locIter = WebGUI::Storage->getCdnFileIterator($session); my $already; # test the object type only once if (is(ref($locIter), 'CODE', 'CDN: getCdnFileIterator to return sub ref')) { while (my $sobj = $locIter->()) { - unless ($already) { - ok($sobj->isa('WebGUI::Storage'), 'CDN: iterator produces Storage objects'); - $already = 1; - } - if ($sobj->getId eq $cdnStorage->getId) { # the one we want to test with - ++$found; - $flist = $sobj->getFiles; - if (is(scalar @$flist, 1, 'CDN: there is one file in the storage')) { - my $file1 = $flist->[0]; - is ($file1, $filename, 'CDN: correct filename in the storage'); - } - } + unless ($already) { + ok($sobj->isa('WebGUI::Storage'), 'CDN: iterator produces Storage objects'); + $already = 1; + } + if ($sobj->getId eq $cdnStorage->getId) { # the one we want to test with + ++$found; + $flist = $sobj->getFiles; + if (is(scalar @$flist, 1, 'CDN: there is one file in the storage')) { + my $file1 = $flist->[0]; + is ($file1, $filename, 'CDN: correct filename in the storage'); + } + } } } is ($found, 1, 'CDN: getCdnFileIterator found storage'); -# TODO: I'm not sure how to make these run on MS-Windows. -# Should we SKIP in the meantime? ($^O eq 'MSWin32') ### syncToCdn $cdnStorage->syncToCdn; ok( (-e $cdnPath and -d $cdnPath), 'CDN: target directory created');