diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index a3f69afef..0afe6e6f0 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -96,6 +96,12 @@
Fix usage of sprintf() due to new constraints in Perl 5.22. Parameters not referenced in the format string are no longer allowed.
+
+
+
+ Log directory create and file open now using FileCommon functions which produce more detailed error messages on failure.
+
+
diff --git a/lib/pgBackRest/Common/Log.pm b/lib/pgBackRest/Common/Log.pm
index a2b77bca6..9f9acb704 100644
--- a/lib/pgBackRest/Common/Log.pm
+++ b/lib/pgBackRest/Common/Log.pm
@@ -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}))
diff --git a/lib/pgBackRest/FileCommon.pm b/lib/pgBackRest/FileCommon.pm
index b274ac8ca..1794501e8 100644
--- a/lib/pgBackRest/FileCommon.pm
+++ b/lib/pgBackRest/FileCommon.pm
@@ -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 = $!;
diff --git a/lib/pgBackRest/RestoreFile.pm b/lib/pgBackRest/RestoreFile.pm
index fec7a7718..db69613dd 100644
--- a/lib/pgBackRest/RestoreFile.pm
+++ b/lib/pgBackRest/RestoreFile.pm
@@ -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});