1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

path_create() working.

This commit is contained in:
David Steele
2014-06-21 15:46:26 -04:00
parent 7bc464a44b
commit 53f1d3c78e
3 changed files with 62 additions and 54 deletions

View File

@ -101,14 +101,29 @@ while ($strCommand ne OP_EXIT)
eval eval
{ {
# File->exists if ($strCommand eq OP_FILE_COPY_OUT)
if ($strCommand eq OP_FILE_EXISTS) {
$oFile->copy(PATH_ABSOLUTE, param_get(\%oParamHash, 'source_file'),
PIPE_STDOUT, undef,
param_get(\%oParamHash, 'source_compressed'), undef);
$oRemote->output_write();
}
elsif ($strCommand eq OP_FILE_COPY_IN)
{
$oFile->copy(PIPE_STDIN, undef,
PATH_ABSOLUTE, param_get(\%oParamHash, 'destination_file'),
undef, param_get(\%oParamHash, 'destination_compress'));
$oRemote->output_write();
}
elsif ($strCommand eq OP_FILE_PATH_CREATE)
{
$oFile->path_create(PATH_ABSOLUTE, param_get(\%oParamHash, 'path'), param_get(\%oParamHash, 'permission', false));
$oRemote->output_write();
}
elsif ($strCommand eq OP_FILE_EXISTS)
{ {
if (!defined($oParamHash{path}))
{
confess "path must be defined";
}
$oRemote->output_write($oFile->exists(PATH_ABSOLUTE, param_get(\%oParamHash, 'path')) ? 'Y' : 'N'); $oRemote->output_write($oFile->exists(PATH_ABSOLUTE, param_get(\%oParamHash, 'path')) ? 'Y' : 'N');
} }
elsif ($strCommand eq OP_FILE_COPY) elsif ($strCommand eq OP_FILE_COPY)
@ -120,22 +135,6 @@ while ($strCommand ne OP_EXIT)
param_get(\%oParamHash, 'destination_compress'), param_get(\%oParamHash, 'destination_compress'),
param_get(\%oParamHash, 'ignore_missing_source', false)) ? 'Y' : 'N'); param_get(\%oParamHash, 'ignore_missing_source', false)) ? 'Y' : 'N');
} }
elsif ($strCommand eq OP_FILE_COPY_IN)
{
$oFile->copy(PIPE_STDIN, undef,
PATH_ABSOLUTE, param_get(\%oParamHash, 'destination_file'),
undef, param_get(\%oParamHash, 'destination_compress'));
$oRemote->output_write();
}
elsif ($strCommand eq OP_FILE_COPY_OUT)
{
$oFile->copy(PATH_ABSOLUTE, param_get(\%oParamHash, 'source_file'),
PIPE_STDOUT, undef,
param_get(\%oParamHash, 'source_compressed'), undef);
$oRemote->output_write();
}
else else
{ {
if ($strCommand ne OP_NOOP) if ($strCommand ne OP_NOOP)

View File

@ -581,6 +581,11 @@ sub path_create
$oParamHash{path} = ${strPathOp}; $oParamHash{path} = ${strPathOp};
if (defined($strPermission))
{
$oParamHash{permission} = ${strPermission};
}
# Add remote info to debug string # Add remote info to debug string
my $strRemote = "remote (" . $self->{oRemote}->command_param_string(\%oParamHash) . ")"; my $strRemote = "remote (" . $self->{oRemote}->command_param_string(\%oParamHash) . ")";
$strDebug = "${strOperation}: ${strRemote}: ${strDebug}"; $strDebug = "${strOperation}: ${strRemote}: ${strDebug}";
@ -592,7 +597,18 @@ sub path_create
else else
{ {
# Attempt the create the directory # Attempt the create the directory
if (!mkdir($strPathOp, oct(defined($strPermission) ? $strPermission : $self->{strDefaultPathPermission}))) my $bResult;
if (defined($strPermission))
{
$bResult = mkdir($strPathOp, oct($strPermission));
}
else
{
$bResult = mkdir($strPathOp);
}
if (!$bResult)
{ {
# Capture the error # Capture the error
my $strError = "${strPath} could not be created: " . $!; my $strError = "${strPath} could not be created: " . $!;
@ -600,12 +616,11 @@ sub path_create
# If running on command line the return directly # If running on command line the return directly
if ($strPathType eq PATH_ABSOLUTE) if ($strPathType eq PATH_ABSOLUTE)
{ {
print $strError; confess &log(ERROR, $!, COMMAND_ERR_PATH_CREATE);
exit COMMAND_ERR_PATH_CREATE;
} }
# Error the normal way # Error the normal way
confess &log(ERROR, "${strDebug}: " . $strError); confess &log(ERROR, "${strDebug}: " . $strError, COMMAND_ERR_PATH_CREATE);
} }
} }
} }

View File

@ -37,7 +37,7 @@ sub BackRestFileTestSetup
my $bDropOnly = shift; my $bDropOnly = shift;
# Remove the backrest private directory # Remove the backrest private directory
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'") == 0 or die 'unable to remove test/private path'; system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/\*'");
# Remove the test directory # Remove the test directory
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path'; system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
@ -105,15 +105,14 @@ sub BackRestFileTest
# Loop through local/remote # Loop through local/remote
for (my $bRemote = 0; $bRemote <= 1; $bRemote++) for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
{ {
# Create the file object
my $oFile = BackRest::File->new my $oFile = BackRest::File->new
( (
strStanza => $strStanza, strStanza => "db",
bNoCompression => true, strBackupClusterPath => undef,
strCommand => $strCommand,
strBackupClusterPath => ${strTestPath},
strBackupPath => ${strTestPath}, strBackupPath => ${strTestPath},
strBackupHost => $bRemote ? $strHost : undef, strRemote => $bRemote ? 'backup' : undef,
strBackupUser => $bRemote ? $strUser : undef oRemote => $bRemote ? $oRemote : undef
); );
# Loop through exists (does the paren path exist?) # Loop through exists (does the paren path exist?)
@ -141,12 +140,12 @@ sub BackRestFileTest
{ {
$strPermission = "0700"; $strPermission = "0700";
# Make sure that we are not testing with the default permission # # Make sure that we are not testing with the default permission
if ($strPermission eq $oFile->{strDefaultPathPermission}) # if ($strPermission eq $oFile->{strDefaultPathPermission})
{ # {
confess 'cannot set test permission ${strPermission} equal to default permission' . # confess 'cannot set test permission ${strPermission} equal to default permission' .
$oFile->{strDefaultPathPermission}; # $oFile->{strDefaultPathPermission};
} # }
} }
# If not exists then set the path to something bogus # If not exists then set the path to something bogus
@ -198,11 +197,12 @@ sub BackRestFileTest
confess "unable to stat ${strPath}"; confess "unable to stat ${strPath}";
} }
my $strPermissionCompare = defined($strPermission) ? $strPermission : $oFile->{strDefaultPathPermission}; if ($bPermission)
if ($strPermissionCompare ne sprintf("%04o", S_IMODE($oStat->mode)))
{ {
confess "permissions were not set to {$strPermissionCompare}"; if ($strPermission ne sprintf("%04o", S_IMODE($oStat->mode)))
{
confess "permissions were not set to {$strPermission}";
}
} }
} }
} }
@ -926,11 +926,6 @@ sub BackRestFileTest
$iRun++; $iRun++;
# if ($iRun != 80)
# {
# next;
# }
&log(INFO, "run ${iRun} - " . &log(INFO, "run ${iRun} - " .
"srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "remote" : "local") . "srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "remote" : "local") .
":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " . ":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " .
@ -938,11 +933,10 @@ sub BackRestFileTest
"dstpth " . (defined($strRemote) && $strRemote eq $strDestinationPath ? "remote" : "local") . "dstpth " . (defined($strRemote) && $strRemote eq $strDestinationPath ? "remote" : "local") .
":${strDestinationPath}, dstcmp $bDestinationCompress"); ":${strDestinationPath}, dstcmp $bDestinationCompress");
# Drop the old test directory and create a new one # Setup test directory
system("rm -rf test"); BackRestFileTestSetup();
system("mkdir -p test/lock") == 0 or confess "Unable to create test/lock directory"; system("mkdir ${strTestPath}/backup") == 0 or confess "Unable to create test/backup directory";
system("mkdir -p test/backup") == 0 or confess "Unable to create test/backup directory"; system("mkdir ${strTestPath}/db") == 0 or confess "Unable to create test/db directory";
system("mkdir -p test/db") == 0 or confess "Unable to create test/db directory";
my $strSourceFile = "${strTestPath}/${strSourcePath}/test-source.txt"; my $strSourceFile = "${strTestPath}/${strSourcePath}/test-source.txt";
my $strDestinationFile = "${strTestPath}/${strDestinationPath}/test-destination.txt"; my $strDestinationFile = "${strTestPath}/${strDestinationPath}/test-destination.txt";