mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
path_create() working.
This commit is contained in:
parent
7bc464a44b
commit
53f1d3c78e
@ -101,14 +101,29 @@ while ($strCommand ne OP_EXIT)
|
||||
|
||||
eval
|
||||
{
|
||||
# File->exists
|
||||
if ($strCommand eq OP_FILE_EXISTS)
|
||||
if ($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();
|
||||
}
|
||||
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');
|
||||
}
|
||||
elsif ($strCommand eq OP_FILE_COPY)
|
||||
@ -120,22 +135,6 @@ while ($strCommand ne OP_EXIT)
|
||||
param_get(\%oParamHash, 'destination_compress'),
|
||||
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
|
||||
{
|
||||
if ($strCommand ne OP_NOOP)
|
||||
|
@ -581,6 +581,11 @@ sub path_create
|
||||
|
||||
$oParamHash{path} = ${strPathOp};
|
||||
|
||||
if (defined($strPermission))
|
||||
{
|
||||
$oParamHash{permission} = ${strPermission};
|
||||
}
|
||||
|
||||
# Add remote info to debug string
|
||||
my $strRemote = "remote (" . $self->{oRemote}->command_param_string(\%oParamHash) . ")";
|
||||
$strDebug = "${strOperation}: ${strRemote}: ${strDebug}";
|
||||
@ -592,7 +597,18 @@ sub path_create
|
||||
else
|
||||
{
|
||||
# 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
|
||||
my $strError = "${strPath} could not be created: " . $!;
|
||||
@ -600,12 +616,11 @@ sub path_create
|
||||
# If running on command line the return directly
|
||||
if ($strPathType eq PATH_ABSOLUTE)
|
||||
{
|
||||
print $strError;
|
||||
exit COMMAND_ERR_PATH_CREATE;
|
||||
confess &log(ERROR, $!, COMMAND_ERR_PATH_CREATE);
|
||||
}
|
||||
|
||||
# Error the normal way
|
||||
confess &log(ERROR, "${strDebug}: " . $strError);
|
||||
confess &log(ERROR, "${strDebug}: " . $strError, COMMAND_ERR_PATH_CREATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ sub BackRestFileTestSetup
|
||||
my $bDropOnly = shift;
|
||||
|
||||
# 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
|
||||
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
|
||||
@ -105,15 +105,14 @@ sub BackRestFileTest
|
||||
# Loop through local/remote
|
||||
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
||||
{
|
||||
# Create the file object
|
||||
my $oFile = BackRest::File->new
|
||||
(
|
||||
strStanza => $strStanza,
|
||||
bNoCompression => true,
|
||||
strCommand => $strCommand,
|
||||
strBackupClusterPath => ${strTestPath},
|
||||
strStanza => "db",
|
||||
strBackupClusterPath => undef,
|
||||
strBackupPath => ${strTestPath},
|
||||
strBackupHost => $bRemote ? $strHost : undef,
|
||||
strBackupUser => $bRemote ? $strUser : undef
|
||||
strRemote => $bRemote ? 'backup' : undef,
|
||||
oRemote => $bRemote ? $oRemote : undef
|
||||
);
|
||||
|
||||
# Loop through exists (does the paren path exist?)
|
||||
@ -141,12 +140,12 @@ sub BackRestFileTest
|
||||
{
|
||||
$strPermission = "0700";
|
||||
|
||||
# Make sure that we are not testing with the default permission
|
||||
if ($strPermission eq $oFile->{strDefaultPathPermission})
|
||||
{
|
||||
confess 'cannot set test permission ${strPermission} equal to default permission' .
|
||||
$oFile->{strDefaultPathPermission};
|
||||
}
|
||||
# # Make sure that we are not testing with the default permission
|
||||
# if ($strPermission eq $oFile->{strDefaultPathPermission})
|
||||
# {
|
||||
# confess 'cannot set test permission ${strPermission} equal to default permission' .
|
||||
# $oFile->{strDefaultPathPermission};
|
||||
# }
|
||||
}
|
||||
|
||||
# If not exists then set the path to something bogus
|
||||
@ -198,11 +197,12 @@ sub BackRestFileTest
|
||||
confess "unable to stat ${strPath}";
|
||||
}
|
||||
|
||||
my $strPermissionCompare = defined($strPermission) ? $strPermission : $oFile->{strDefaultPathPermission};
|
||||
|
||||
if ($strPermissionCompare ne sprintf("%04o", S_IMODE($oStat->mode)))
|
||||
if ($bPermission)
|
||||
{
|
||||
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++;
|
||||
|
||||
# if ($iRun != 80)
|
||||
# {
|
||||
# next;
|
||||
# }
|
||||
|
||||
&log(INFO, "run ${iRun} - " .
|
||||
"srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "remote" : "local") .
|
||||
":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " .
|
||||
@ -938,11 +933,10 @@ sub BackRestFileTest
|
||||
"dstpth " . (defined($strRemote) && $strRemote eq $strDestinationPath ? "remote" : "local") .
|
||||
":${strDestinationPath}, dstcmp $bDestinationCompress");
|
||||
|
||||
# Drop the old test directory and create a new one
|
||||
system("rm -rf test");
|
||||
system("mkdir -p test/lock") == 0 or confess "Unable to create test/lock directory";
|
||||
system("mkdir -p test/backup") == 0 or confess "Unable to create test/backup directory";
|
||||
system("mkdir -p test/db") == 0 or confess "Unable to create test/db directory";
|
||||
# Setup test directory
|
||||
BackRestFileTestSetup();
|
||||
system("mkdir ${strTestPath}/backup") == 0 or confess "Unable to create test/backup directory";
|
||||
system("mkdir ${strTestPath}/db") == 0 or confess "Unable to create test/db directory";
|
||||
|
||||
my $strSourceFile = "${strTestPath}/${strSourcePath}/test-source.txt";
|
||||
my $strDestinationFile = "${strTestPath}/${strDestinationPath}/test-destination.txt";
|
||||
|
Loading…
Reference in New Issue
Block a user