You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-12-01 22:30:09 +02:00
Remove LibC.
This was the interface between Perl and C introduced in36a5349bbut sincef0ef73dbhas only been used by the Perl integration tests. This is expensive code to maintain just for testing. The main dependency was the interface to storage, no matter where it was located, e.g. S3. Replace this with the new-introduced repo commands (d3c83453) that allow access to repo storage via the command line. The other dependency was on various cfgOption* functions and CFGOPT_ constants that were convenient but not necessary. Replace these with hard-coded strings in most places and create new constants for commonly used values. Remove all auto-generated Perl code. This means that the error list will no longer be maintained automatically so copy used errors to Common::Exception.pm. This file will need to be maintained manually going forward but there is not likely to be much churn as the Perl integration tests are being retired. Update test.pl and related code to remove LibC builds. Ding, dong, LibC is dead.
This commit is contained in:
@@ -69,6 +69,85 @@ sub new
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Copy a file. If special encryption settings are required, then the file objects from openRead/openWrite must be passed instead of
|
||||
# file names.
|
||||
####################################################################################################################################
|
||||
sub copy
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$xSourceFile,
|
||||
$xDestinationFile,
|
||||
$bSourceOpen,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->copy', \@_,
|
||||
{name => 'xSourceFile', required => false},
|
||||
{name => 'xDestinationFile'},
|
||||
{name => 'bSourceOpen', optional => true, default => false},
|
||||
);
|
||||
|
||||
# Is source/destination an IO object or a file expression?
|
||||
my $oSourceFileIo = defined($xSourceFile) ? (ref($xSourceFile) ? $xSourceFile : $self->openRead($xSourceFile)) : undef;
|
||||
|
||||
# Does the source file exist?
|
||||
my $bResult = false;
|
||||
|
||||
# Copy if the source file exists
|
||||
if (defined($oSourceFileIo))
|
||||
{
|
||||
my $oDestinationFileIo = ref($xDestinationFile) ? $xDestinationFile : $self->openWrite($xDestinationFile);
|
||||
|
||||
# Use C copy if source and destination are C objects
|
||||
if (defined($oSourceFileIo->{oStorageCRead}) && defined($oDestinationFileIo->{oStorageCWrite}))
|
||||
{
|
||||
$bResult = $self->{oStorageC}->copy(
|
||||
$oSourceFileIo->{oStorageCRead}, $oDestinationFileIo->{oStorageCWrite}) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
# Open the source file if it is a C object
|
||||
$bResult = defined($oSourceFileIo->{oStorageCRead}) ? ($bSourceOpen || $oSourceFileIo->open()) : true;
|
||||
|
||||
if ($bResult)
|
||||
{
|
||||
# Open the destination file if it is a C object
|
||||
if (defined($oDestinationFileIo->{oStorageCWrite}))
|
||||
{
|
||||
$oDestinationFileIo->open();
|
||||
}
|
||||
|
||||
# Copy the data
|
||||
do
|
||||
{
|
||||
# Read data
|
||||
my $tBuffer = '';
|
||||
|
||||
$oSourceFileIo->read(\$tBuffer, $self->{lBufferMax});
|
||||
$oDestinationFileIo->write(\$tBuffer);
|
||||
}
|
||||
while (!$oSourceFileIo->eof());
|
||||
|
||||
# Close files
|
||||
$oSourceFileIo->close();
|
||||
$oDestinationFileIo->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'bResult', value => $bResult, trace => true},
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# exists - check if file exists
|
||||
####################################################################################################################################
|
||||
@@ -99,6 +178,62 @@ sub exists
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# get - reads a buffer from storage all at once
|
||||
####################################################################################################################################
|
||||
sub get
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$xFile,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->get', \@_,
|
||||
{name => 'xFile', required => false, trace => true},
|
||||
);
|
||||
|
||||
# Is this an IO object or a file expression? If file expression, then open the file and pass passphrase if one is defined or
|
||||
# if the repo has a user passphrase defined - else pass undef
|
||||
my $oFileIo = defined($xFile) ? (ref($xFile) ? $xFile : $self->openRead($xFile)) : undef;
|
||||
|
||||
# Read only if there is something to read from
|
||||
my $tContent;
|
||||
my $lSize = 0;
|
||||
|
||||
if (defined($oFileIo))
|
||||
{
|
||||
my $lSizeRead;
|
||||
|
||||
do
|
||||
{
|
||||
$lSizeRead = $oFileIo->read(\$tContent, $self->{lBufferMax});
|
||||
$lSize += $lSizeRead;
|
||||
}
|
||||
while ($lSizeRead != 0);
|
||||
|
||||
# Close the file
|
||||
$oFileIo->close();
|
||||
|
||||
# If nothing was read then set to undef
|
||||
if ($lSize == 0)
|
||||
{
|
||||
$tContent = undef;
|
||||
}
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'rtContent', value => defined($oFileIo) ? \$tContent : undef, trace => true},
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# info - get information for path/file
|
||||
####################################################################################################################################
|
||||
@@ -595,6 +730,56 @@ sub pathSync
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# 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,
|
||||
$xFile,
|
||||
$xContent,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->put', \@_,
|
||||
{name => 'xFile', trace => true},
|
||||
{name => 'xContent', required => false, trace => true},
|
||||
);
|
||||
|
||||
# Is this an IO object or a file expression? If file expression, then open the file and pass passphrase if one is defined or if
|
||||
# the repo has a user passphrase defined - else pass undef
|
||||
my $oFileIo = ref($xFile) ? $xFile : $self->openWrite($xFile);
|
||||
|
||||
# Determine size of content
|
||||
my $lSize = defined($xContent) ? length(ref($xContent) ? $$xContent : $xContent) : 0;
|
||||
|
||||
# Write only if there is something to write
|
||||
if ($lSize > 0)
|
||||
{
|
||||
$oFileIo->write(ref($xContent) ? $xContent : \$xContent);
|
||||
}
|
||||
# Else open the file so a zero length file is created (since file is not opened until first write)
|
||||
else
|
||||
{
|
||||
$oFileIo->open();
|
||||
}
|
||||
|
||||
# Close the file
|
||||
$oFileIo->close();
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'lSize', value => $lSize, trace => true},
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# remove - remove path/file
|
||||
####################################################################################################################################
|
||||
@@ -647,7 +832,6 @@ sub remove
|
||||
####################################################################################################################################
|
||||
sub pathBase {shift->{strPathBase}}
|
||||
sub driver {shift->{oDriver}}
|
||||
sub cipherType {undef}
|
||||
sub cipherPassUser {undef}
|
||||
sub type {shift->{oDriver}->type()}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user