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:
David Steele
2016-05-26 15:04:18 -04:00
parent e4e885d602
commit 379ab1b353
4 changed files with 18 additions and 11 deletions
+6
View File
@@ -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>
+6 -7
View File
@@ -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}))
+5 -3
View File
@@ -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 = $!;
+1 -1
View File
@@ -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});