2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2019-06-26 14:24:58 +02:00
|
|
|
# C Storage Interface
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-10 21:12:44 +02:00
|
|
|
package pgBackRestTest::Common::StorageRepo;
|
|
|
|
use parent 'pgBackRestTest::Common::StorageBase';
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
2020-03-06 01:34:59 +02:00
|
|
|
use Digest::SHA qw(sha1_hex);
|
2020-03-10 21:12:44 +02:00
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
2017-06-09 23:51:41 +02:00
|
|
|
use File::Basename qw(dirname);
|
2019-06-26 14:24:58 +02:00
|
|
|
use Fcntl qw(:mode);
|
|
|
|
use File::stat qw{lstat};
|
|
|
|
use JSON::PP;
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
|
|
use pgBackRestDoc::Common::Log;
|
2020-03-10 23:57:02 +02:00
|
|
|
use pgBackRestDoc::ProjectInfo;
|
2020-03-10 21:12:44 +02:00
|
|
|
|
|
|
|
use pgBackRestTest::Common::Io::Handle;
|
|
|
|
use pgBackRestTest::Common::Io::Process;
|
|
|
|
use pgBackRestTest::Common::StorageBase;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Temp file extension
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant STORAGE_TEMP_EXT => PROJECT_EXE . '.tmp';
|
|
|
|
push @EXPORT, qw(STORAGE_TEMP_EXT);
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# new
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift;
|
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
2019-06-26 14:24:58 +02:00
|
|
|
my $strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->{strCommand},
|
2019-06-26 14:24:58 +02:00
|
|
|
$self->{strType},
|
|
|
|
$self->{lBufferMax},
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->{iTimeoutIo},
|
2019-06-26 14:24:58 +02:00
|
|
|
$self->{strDefaultPathMode},
|
|
|
|
$self->{strDefaultFileMode},
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->new', \@_,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strCommand'},
|
2019-06-26 14:24:58 +02:00
|
|
|
{name => 'strType'},
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'lBufferMax'},
|
|
|
|
{name => 'iTimeoutIo'},
|
2017-06-09 23:51:41 +02:00
|
|
|
{name => 'strDefaultPathMode', optional => true, default => '0750'},
|
|
|
|
{name => 'strDefaultFileMode', optional => true, default => '0640'},
|
|
|
|
);
|
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
# Create JSON object
|
|
|
|
$self->{oJSON} = JSON::PP->new()->allow_nonref();
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Escape characteres that have special meaning on the command line
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub escape
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strValue,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->escape', \@_,
|
|
|
|
{name => 'strValue', trace => true},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$strValue =~ s/\\/\\\\/g;
|
|
|
|
$strValue =~ s/\</\\\</g;
|
|
|
|
$strValue =~ s/\>/\\\>/g;
|
|
|
|
$strValue =~ s/\!/\\\!/g;
|
|
|
|
$strValue =~ s/\*/\\\*/g;
|
|
|
|
$strValue =~ s/\(/\\\(/g;
|
|
|
|
$strValue =~ s/\)/\\\)/g;
|
|
|
|
$strValue =~ s/\&/\\\&/g;
|
|
|
|
$strValue =~ s/\'/\\\'/g;
|
|
|
|
$strValue =~ s/\;/\\\;/g;
|
|
|
|
$strValue =~ s/\?/\\\?/g;
|
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strValue', value => $strValue},
|
2019-06-26 14:24:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Execute command and return the output
|
2019-06-26 14:24:58 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub exec
|
2019-06-26 14:24:58 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strCommand,
|
2019-06-26 14:24:58 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->exec', \@_,
|
|
|
|
{name => 'strCommand'},
|
2019-06-26 14:24:58 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$strCommand = "$self->{strCommand} ${strCommand}";
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oBuffer = new pgBackRestTest::Common::Io::Buffered(
|
|
|
|
new pgBackRestTest::Common::Io::Handle($strCommand), $self->{iTimeoutIo}, $self->{lBufferMax});
|
|
|
|
my $oProcess = new pgBackRestTest::Common::Io::Process($oBuffer, $strCommand);
|
2019-06-26 14:24:58 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
my $tResult;
|
2019-06-26 14:24:58 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
while (!$oBuffer->eof())
|
2019-06-26 14:24:58 +02:00
|
|
|
{
|
2020-03-09 23:41:59 +02:00
|
|
|
$oBuffer->read(\$tResult, $self->{lBufferMax}, false);
|
2019-06-26 14:24:58 +02:00
|
|
|
}
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$oProcess->close();
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'tResult', value => $tResult},
|
|
|
|
{name => 'iExitStatus', value => $oProcess->exitStatus()},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Create storage
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub create
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
2020-03-09 23:41:59 +02:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->create');
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->exec("repo-create");
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2020-03-09 23:41:59 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2017-06-09 23:51:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Check if file exists (not a path)
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub exists
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strFileExp,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->exists', \@_,
|
|
|
|
{name => 'strFileExp'},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'bExists', value => $self->info($strFileExp, {bIgnoreMissing => true})->{type} eq 'f'}
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Read a buffer from storage all at once
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub get
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$xFile,
|
|
|
|
$strCipherPass,
|
|
|
|
$bRaw,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->get', \@_,
|
|
|
|
{name => 'xFile', required => false},
|
|
|
|
{name => 'strCipherPass', optional => true, redact => true},
|
|
|
|
{name => 'bRaw', optional => true, default => false},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
# If openRead() was called first set values from that call
|
|
|
|
my $strFile = $xFile;
|
|
|
|
my $bIgnoreMissing = false;
|
|
|
|
|
|
|
|
if (ref($xFile))
|
|
|
|
{
|
|
|
|
$strFile = $xFile->{strFile};
|
|
|
|
$bIgnoreMissing = $xFile->{bIgnoreMissing};
|
|
|
|
$strCipherPass = $xFile->{strCipherPass};
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check invalid params
|
|
|
|
if ($bRaw && defined($strCipherPass))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'bRaw and strCipherPass cannot both be set');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get file
|
|
|
|
my ($tResult, $iExitStatus) = $self->exec(
|
|
|
|
(defined($strCipherPass) ? ' --cipher-pass=' . $self->escape($strCipherPass) : '') . ($bRaw ? ' --raw' : '') .
|
|
|
|
($bIgnoreMissing ? ' --ignore-missing' : '') . ' repo-get ' . $self->escape($strFile));
|
|
|
|
|
|
|
|
# Error if missing an not ignored
|
|
|
|
if ($iExitStatus == 1 && !$bIgnoreMissing)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to open '${strFile}'", ERROR_FILE_OPEN);
|
|
|
|
}
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'rtContent', value => $iExitStatus == 0 ? \$tResult : undef, trace => true},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Get information for path/file
|
|
|
|
####################################################################################################################################
|
|
|
|
sub info
|
2019-09-03 18:30:45 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strPathFileExp,
|
|
|
|
$bIgnoreMissing,
|
2019-09-03 18:30:45 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->info', \@_,
|
|
|
|
{name => 'strPathFileExp'},
|
|
|
|
{name => 'bIgnoreMissing', optional => true, default => false},
|
2019-09-03 18:30:45 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'rhInfo', value => $self->manifest($strPathFileExp, {bRecurse => false})->{'.'}, trace => true}
|
2019-09-03 18:30:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# List all files/paths in path
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub list
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strPathExp,
|
|
|
|
$strExpression,
|
|
|
|
$strSortOrder,
|
2017-06-09 23:51:41 +02:00
|
|
|
$bIgnoreMissing,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->list', \@_,
|
|
|
|
{name => 'strPathExp', required => false},
|
|
|
|
{name => 'strExpression', optional => true},
|
|
|
|
{name => 'strSortOrder', optional => true, default => 'forward'},
|
2017-06-09 23:51:41 +02:00
|
|
|
{name => 'bIgnoreMissing', optional => true, default => false},
|
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
# Get file list
|
|
|
|
my $rstryFileList = [];
|
|
|
|
my $rhManifest = $self->manifest($strPathExp, {bRecurse => false});
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
foreach my $strKey ($strSortOrder eq 'reverse' ? sort {$b cmp $a} keys(%{$rhManifest}) : sort keys(%{$rhManifest}))
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
2020-03-09 23:41:59 +02:00
|
|
|
next if $strKey eq '.';
|
|
|
|
next if defined($strExpression) && $strKey !~ $strExpression;
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
push(@{$rstryFileList}, $strKey);
|
2017-06-09 23:51:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'stryFileList', value => $rstryFileList}
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Build path/file/link manifest starting with base path and including all subpaths
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub manifest
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strPathExp,
|
|
|
|
$bRecurse,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->manifest', \@_,
|
|
|
|
{name => 'strPathExp'},
|
|
|
|
{name => 'bRecurse', optional => true, default => true},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
my $rhManifest = $self->{oJSON}->decode(
|
|
|
|
$self->exec("--output=json " . ($bRecurse ? ' --recurse' : '') . " repo-ls " . $self->escape($strPathExp)));
|
2017-11-06 19:51:12 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
# Transform the manifest to the old format
|
|
|
|
foreach my $strKey (keys(%{$rhManifest}))
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
2020-03-09 23:41:59 +02:00
|
|
|
if ($rhManifest->{$strKey}{type} eq 'file')
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
2020-03-09 23:41:59 +02:00
|
|
|
$rhManifest->{$strKey}{type} = 'f';
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
if (defined($rhManifest->{$strKey}{time}))
|
|
|
|
{
|
|
|
|
$rhManifest->{$strKey}{modified_time} = $rhManifest->{$strKey}{time};
|
|
|
|
delete($rhManifest->{$strKey}{time});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($rhManifest->{$strKey}{type} eq 'path')
|
|
|
|
{
|
|
|
|
$rhManifest->{$strKey}{type} = 'd';
|
|
|
|
}
|
|
|
|
elsif ($rhManifest->{$strKey}{type} eq 'link')
|
|
|
|
{
|
|
|
|
$rhManifest->{$strKey}{type} = 'l';
|
|
|
|
}
|
|
|
|
elsif ($rhManifest->{$strKey}{type} eq 'special')
|
|
|
|
{
|
|
|
|
$rhManifest->{$strKey}{type} = 's';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess "invalid file type '$rhManifest->{type}'";
|
|
|
|
}
|
2019-06-26 14:24:58 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'rhManifest', value => $rhManifest, trace => true}
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
# Open file for reading
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2020-03-09 23:41:59 +02:00
|
|
|
sub openRead
|
2017-06-09 23:51:41 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strFile,
|
|
|
|
$bIgnoreMissing,
|
|
|
|
$strCipherPass,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
2019-06-26 14:24:58 +02:00
|
|
|
(
|
2020-03-09 23:41:59 +02:00
|
|
|
__PACKAGE__ . '->openRead', \@_,
|
|
|
|
{name => 'strFile'},
|
|
|
|
{name => 'bIgnoreMissing', optional => true, default => false},
|
|
|
|
{name => 'strCipherPass', optional => true, redact => true},
|
2019-06-26 14:24:58 +02:00
|
|
|
);
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'rhFileIo', value => {strFile => $strFile, bIgnoreMissing => $bIgnoreMissing, strCipherPass => $strCipherPass},
|
|
|
|
trace => true},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-26 14:24:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Remove path and all files below it
|
|
|
|
####################################################################################################################################
|
|
|
|
sub pathRemove
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strPath,
|
2019-06-26 14:24:58 +02:00
|
|
|
$bRecurse,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->pathRemove', \@_,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strPath'},
|
2019-06-26 14:24:58 +02:00
|
|
|
{name => 'bRecurse', optional => true, default => false},
|
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->exec("repo-rm " . ($bRecurse ? '--recurse ' : '') . $self->escape($strPath));
|
2019-06-26 14:24:58 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
2019-06-26 14:24:58 +02:00
|
|
|
# put - writes a buffer out to storage all at once
|
|
|
|
####################################################################################################################################
|
|
|
|
sub put
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strFile,
|
|
|
|
$tContent,
|
2019-06-26 14:24:58 +02:00
|
|
|
$strCipherPass,
|
2020-03-09 23:41:59 +02:00
|
|
|
$bRaw,
|
2019-06-26 14:24:58 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->put', \@_,
|
2020-03-09 23:41:59 +02:00
|
|
|
{name => 'strFile'},
|
|
|
|
{name => 'tContent', required => false},
|
|
|
|
{name => 'strCipherPass', optional => true, redact => true},
|
|
|
|
{name => 'bRaw', optional => true, default => false},
|
2019-06-26 14:24:58 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
# Check invalid params
|
|
|
|
if ($bRaw && defined($strCipherPass))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'bRaw and strCipherPass cannot both be set');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Put file
|
|
|
|
my $strCommand =
|
|
|
|
"$self->{strCommand}" . (defined($strCipherPass) ? ' --cipher-pass=' . $self->escape($strCipherPass) : '') .
|
|
|
|
($bRaw ? ' --raw' : '') . ' repo-put ' . $self->escape($strFile);
|
|
|
|
|
2020-03-10 21:12:44 +02:00
|
|
|
my $oBuffer = new pgBackRestTest::Common::Io::Buffered(
|
|
|
|
new pgBackRestTest::Common::Io::Handle($strCommand), $self->{iTimeoutIo}, $self->{lBufferMax});
|
|
|
|
my $oProcess = new pgBackRestTest::Common::Io::Process($oBuffer, $strCommand);
|
2020-03-09 23:41:59 +02:00
|
|
|
|
|
|
|
if (defined($tContent))
|
|
|
|
{
|
|
|
|
$oBuffer->write(\$tContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
close($oBuffer->handleWrite());
|
|
|
|
|
|
|
|
my $tResult;
|
|
|
|
|
|
|
|
while (!$oBuffer->eof())
|
|
|
|
{
|
|
|
|
$oBuffer->read(\$tResult, $self->{lBufferMax}, false);
|
|
|
|
}
|
2019-06-26 14:24:58 +02:00
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
close($oBuffer->handleRead());
|
|
|
|
$oProcess->close();
|
2019-06-26 14:24:58 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2020-03-09 23:41:59 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2019-06-26 14:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Remove file
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub remove
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2020-03-09 23:41:59 +02:00
|
|
|
$strFile,
|
2017-06-09 23:51:41 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->remove', \@_,
|
2019-06-26 14:24:58 +02:00
|
|
|
{name => 'xFileExp'},
|
2017-06-09 23:51:41 +02:00
|
|
|
);
|
|
|
|
|
2020-03-09 23:41:59 +02:00
|
|
|
$self->exec("repo-rm " . $self->escape($strFile));
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
2019-06-26 14:24:58 +02:00
|
|
|
return logDebugReturn($strOperation);
|
2017-06-09 23:51:41 +02:00
|
|
|
}
|
|
|
|
|
2020-03-10 21:12:44 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Cache storage so it can be retrieved quickly
|
|
|
|
####################################################################################################################################
|
|
|
|
my $oRepoStorage;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageRepoCommandSet
|
|
|
|
####################################################################################################################################
|
|
|
|
my $strStorageRepoCommand;
|
|
|
|
my $strStorageRepoType;
|
|
|
|
|
|
|
|
sub storageRepoCommandSet
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strCommand,
|
|
|
|
$strStorageType,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageRepoCommandSet', \@_,
|
|
|
|
{name => 'strCommand'},
|
|
|
|
{name => 'strStorageType'},
|
|
|
|
);
|
|
|
|
|
|
|
|
$strStorageRepoCommand = $strCommand;
|
|
|
|
$strStorageRepoType = $strStorageType;
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepoCommandSet);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# storageRepo - get repository storage
|
|
|
|
####################################################################################################################################
|
|
|
|
sub storageRepo
|
|
|
|
{
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strStanza,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '::storageRepo', \@_,
|
|
|
|
{name => 'strStanza', optional => true, trace => true},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Create storage if not defined
|
|
|
|
if (!defined($oRepoStorage))
|
|
|
|
{
|
|
|
|
$oRepoStorage = new pgBackRestTest::Common::StorageRepo($strStorageRepoCommand, $strStorageRepoType, 64 * 1024, 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'oStorageRepo', value => $oRepoStorage, trace => true},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(storageRepo);
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Getters
|
|
|
|
####################################################################################################################################
|
2019-06-26 14:24:58 +02:00
|
|
|
sub capability {shift->type() eq STORAGE_POSIX}
|
2020-03-09 23:41:59 +02:00
|
|
|
sub type {shift->{strType}}
|
2017-06-09 23:51:41 +02:00
|
|
|
|
|
|
|
1;
|