mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Closed #170: Write .info and .manifest files to temp before moving to final location and syncing
This commit is contained in:
parent
17cbab524a
commit
053f25d870
@ -116,6 +116,8 @@ use constant ERROR_HOST_INVALID => ERROR_MIN
|
||||
push @EXPORT, qw(ERROR_HOST_INVALID);
|
||||
use constant ERROR_PATH_MISSING => ERROR_MINIMUM + 48;
|
||||
push @EXPORT, qw(ERROR_PATH_MISSING);
|
||||
use constant ERROR_FILE_MOVE => ERROR_MINIMUM + 49;
|
||||
push @EXPORT, qw(ERROR_FILE_MOVE);
|
||||
|
||||
use constant ERROR_INVALID_VALUE => ERROR_MAXIMUM - 1;
|
||||
push @EXPORT, qw(ERROR_INVALID_VALUE);
|
||||
|
@ -210,7 +210,7 @@ sub save
|
||||
my $self = shift;
|
||||
|
||||
$self->hash();
|
||||
iniSave($self->{strFileName}, $self->{oContent});
|
||||
iniSave($self->{strFileName}, $self->{oContent}, false, true);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@ -228,22 +228,25 @@ sub iniSave
|
||||
$strOperation,
|
||||
$strFileName,
|
||||
$oContent,
|
||||
$bRelaxed
|
||||
$bRelaxed,
|
||||
$bTemp
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
OP_INI_INI_SAVE, \@_,
|
||||
{name => 'strFileName', trace => true},
|
||||
{name => 'oContent', trace => true},
|
||||
{name => 'bRelaxed', required => false, trace => true}
|
||||
{name => 'bRelaxed', required => false, trace => true},
|
||||
{name => 'bTemp', required => false, trace => true}
|
||||
);
|
||||
|
||||
# Open the ini file for writing
|
||||
my $strFileTemp = $bTemp ? "${strFileName}.new" : $strFileName;
|
||||
my $hFile;
|
||||
my $bFirst = true;
|
||||
|
||||
sysopen($hFile, $strFileName, O_WRONLY | O_CREAT | O_TRUNC, 0640)
|
||||
or confess &log(ERROR, "unable to open ${strFileName}");
|
||||
sysopen($hFile, $strFileTemp, O_WRONLY | O_CREAT | O_TRUNC, 0640)
|
||||
or confess &log(ERROR, "unable to open ${strFileTemp}");
|
||||
|
||||
# Create the JSON object canonical so that fields are alpha ordered to pass unit tests
|
||||
my $oJSON = JSON::PP->new()->canonical()->allow_nonref();
|
||||
@ -304,11 +307,20 @@ sub iniSave
|
||||
$bFirst = false;
|
||||
}
|
||||
|
||||
# Sync and close ini file
|
||||
# Sync and close temp file
|
||||
$hFile->sync();
|
||||
filePathSync(dirname($strFileName));
|
||||
close($hFile);
|
||||
|
||||
# Rename temp file to ini file
|
||||
if ($bTemp && !rename($strFileTemp, $strFileName))
|
||||
{
|
||||
unlink($strFileTemp);
|
||||
confess &log(ERROR, "unable to move ${strFileTemp} to ${strFileName}", ERROR_FILE_MOVE);
|
||||
}
|
||||
|
||||
# Sync the directory to make sure the changes stick
|
||||
filePathSync(dirname($strFileName));
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
|
@ -146,15 +146,15 @@ sub fileStringWrite
|
||||
syswrite($hFile, $strContent)
|
||||
or confess &log(ERROR, "unable to write string to ${strFileName}: $!", ERROR_FILE_WRITE);
|
||||
|
||||
# Sync and close ini file
|
||||
if ($bSync)
|
||||
{
|
||||
$hFile->sync();
|
||||
filePathSync(dirname($strFileName));
|
||||
}
|
||||
# Sync file
|
||||
$hFile->sync() if $bSync;
|
||||
|
||||
# Close file
|
||||
close($hFile);
|
||||
|
||||
# Sync directory
|
||||
filePathSync(dirname($strFileName)) if $bSync;
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
|
Loading…
x
Reference in New Issue
Block a user