From 2aa516fd648e9d7d16260bfb9fb29981f5e96a8a Mon Sep 17 00:00:00 2001 From: Simone Di Maulo Date: Fri, 15 Feb 2019 23:01:48 +0100 Subject: [PATCH] Fix logfile open filemode (#5354) Fixes #5346 --- logger/logfile.go | 2 +- logger/logfile_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/logger/logfile.go b/logger/logfile.go index 9451f0f835..c211ef16b0 100644 --- a/logger/logfile.go +++ b/logger/logfile.go @@ -54,7 +54,7 @@ func (l *LogFile) openNew() error { newfileName := fileName + "-" + strconv.FormatInt(createTime.UnixNano(), 10) + fileExt newfilePath := filepath.Join(l.logPath, newfileName) // Try creating a file. We truncate the file because we are the only authority to write the logs - filePointer, err := os.OpenFile(newfilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 640) + filePointer, err := os.OpenFile(newfilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640) if err != nil { return err } diff --git a/logger/logfile_test.go b/logger/logfile_test.go index c6ebc2907e..0714497bf3 100644 --- a/logger/logfile_test.go +++ b/logger/logfile_test.go @@ -29,6 +29,21 @@ func TestLogFile_timeRotation(t *testing.T) { } } +func TestLogFile_openNew(t *testing.T) { + t.Parallel() + tempDir := testutil.TempDir(t, "LogWriterOpen") + defer os.Remove(tempDir) + logFile := LogFile{fileName: testFileName, logPath: tempDir, duration: testDuration} + + if err := logFile.openNew(); err != nil { + t.Errorf("Expected open file %s, got an error (%s)", testFileName, err) + } + + if _, err := ioutil.ReadFile(logFile.FileInfo.Name()); err != nil { + t.Errorf("Expected readable file %s, got an error (%s)", logFile.FileInfo.Name(), err) + } +} + func TestLogFile_byteRotation(t *testing.T) { t.Parallel() tempDir := testutil.TempDir(t, "LogWriterBytes")