mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +02:00
Improve log directory/file creation.
Log directory create and file open now using FileCommon functions which produce more detailed error messages on failure.
This commit is contained in:
@@ -96,6 +96,12 @@
|
||||
<p>Fix usage of sprintf() due to new constraints in Perl 5.22. Parameters not referenced in the format string are no longer allowed.</p>
|
||||
</release-item>
|
||||
</release-bug-list>
|
||||
|
||||
<release-refactor-list>
|
||||
<release-item>
|
||||
<p>Log directory create and file open now using FileCommon functions which produce more detailed error messages on failure.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-core-list>
|
||||
|
||||
<release-doc-list>
|
||||
|
||||
@@ -107,11 +107,7 @@ sub logFileSet
|
||||
# Only open the log file if file logging is enabled
|
||||
if ($strLogLevelFile ne OFF)
|
||||
{
|
||||
unless (-e dirname($strFile))
|
||||
{
|
||||
mkdir(dirname($strFile), oct('0770'))
|
||||
or die "unable to create directory " . dirname($strFile) . " for log file ${strFile}";
|
||||
}
|
||||
filePathCreate(dirname($strFile), '0770', true, true);
|
||||
|
||||
$strFile .= '.log';
|
||||
my $bExists = false;
|
||||
@@ -121,8 +117,7 @@ sub logFileSet
|
||||
$bExists = true;
|
||||
}
|
||||
|
||||
sysopen($hLogFile, $strFile, O_WRONLY | O_CREAT | O_APPEND, 0660)
|
||||
or confess &log(ERROR, "unable to open log file ${strFile}", ERROR_FILE_OPEN);
|
||||
$hLogFile = fileOpen($strFile, O_WRONLY | O_CREAT | O_APPEND, '0660');
|
||||
|
||||
if ($bExists)
|
||||
{
|
||||
@@ -143,6 +138,10 @@ sub logLevelSet
|
||||
my $strLevelFileParam = shift;
|
||||
my $strLevelConsoleParam = shift;
|
||||
|
||||
# Load FileCommon module
|
||||
require pgBackRest::FileCommon;
|
||||
pgBackRest::FileCommon->import();
|
||||
|
||||
if (defined($strLevelFileParam))
|
||||
{
|
||||
if (!defined($oLogLevelRank{uc($strLevelFileParam)}{rank}))
|
||||
|
||||
@@ -363,18 +363,20 @@ sub fileOpen
|
||||
(
|
||||
$strOperation,
|
||||
$strFile,
|
||||
$lFlags
|
||||
$lFlags,
|
||||
$strMode,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '::fileOpen', \@_,
|
||||
{name => 'strFile', trace => true},
|
||||
{name => 'lFlags', trace => true}
|
||||
{name => 'lFlags', trace => true},
|
||||
{name => 'strMode', default => '0640', trace => true},
|
||||
);
|
||||
|
||||
my $hFile;
|
||||
|
||||
if (!sysopen($hFile, $strFile, $lFlags))
|
||||
if (!sysopen($hFile, $strFile, $lFlags, oct($strMode)))
|
||||
{
|
||||
my $strError = $!;
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ sub restoreFile
|
||||
$bZero = true;
|
||||
|
||||
# Open the file truncating to zero bytes in case it already exists
|
||||
my $hFile = fileOpen($$oFileHash{db_file}, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
my $hFile = fileOpen($$oFileHash{db_file}, O_WRONLY | O_CREAT | O_TRUNC, $$oFileHash{mode});
|
||||
|
||||
# Now truncate to the original size. This will create a sparse file which is very efficient for this use case.
|
||||
truncate($hFile, $$oFileHash{size});
|
||||
|
||||
Reference in New Issue
Block a user