App-FuguVM
view release on metacpan or search on metacpan
lib/App/FuguVM/Remote.pm view on Meta::CPAN
$source
);
$failed = 1;
return;
}
if ( -d $source ) {
# Fail closed: a directory that
# the walk cannot enter would
# read as a complete copy.
if ( !-r $source || !-x $source ) {
Fugu::Log->default->error(
'Cannot enter'
. ' directory: %s',
$source );
$failed = 1;
$File::Find::prune = 1;
return;
}
push @entries,
{ type => 'dir', dest => $dest };
return;
}
if ( !-f $source ) {
Fugu::Log->default->error(
'Not a regular file: %s',
$source );
$failed = 1;
return;
}
$add_file->( $source, $dest );
},
},
$local
);
return if $failed;
my @sorted =
sort { $a->{dest} cmp $b->{dest} } @entries;
return \@sorted;
}
# $self->_mkdir(@dirs):
# Create every remote directory, batched under BATCH_PATHS
# paths for each call. The method returns 1, or undef.
sub _mkdir ( $self, @dirs )
{
while (@dirs) {
my @batch = splice @dirs, 0, BATCH_PATHS;
my $result =
$self->{ssh}
->run_command( $self->quote_argv( 'mkdir', '-p', @batch ) );
if ( $result->{exit_code} != 0 ) {
Fugu::Log->default->error(
'Cannot create directories on %s:%d: %s',
$self->{host}, $self->{port},
$result->{stderr} );
return;
}
}
return 1;
}
# $self->_publish(@files):
# Move every temporary file onto its destination, with batched
# mv -f commands. Each mv holds two paths, so one batch holds
# BATCH_PATHS / 2 moves. The method returns 1, or undef.
sub _publish ( $self, @files )
{
my @pairs = map { [ "$_->{dest}.fuguvm.$$", $_->{dest} ] } @files;
while (@pairs) {
my @batch = splice @pairs, 0, int( BATCH_PATHS / 2 );
my $command = join ' && ',
map { $self->quote_argv( 'mv', '-f', $_->[0], $_->[1] ) }
@batch;
my $result = $self->{ssh}->run_command($command);
if ( $result->{exit_code} != 0 ) {
Fugu::Log->default->error(
'Cannot publish files on %s:%d: %s',
$self->{host}, $self->{port},
$result->{stderr} );
return;
}
}
return 1;
}
# $self->_discard(@temps):
# Remove the temporary files that a failed put wrote, with
# batched rm -f commands. The removal is best effort: the
# caller already reports the failure that got it here.
sub _discard ( $self, @temps )
{
while (@temps) {
my @batch = splice @temps, 0, BATCH_PATHS;
$self->{ssh}
->run_command( $self->quote_argv( 'rm', '-f', @batch ) );
}
return;
}
1;
( run in 1.283 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )