Fix logfile open filemode (#5354)

Fixes #5346
This commit is contained in:
Simone Di Maulo 2019-02-15 23:01:48 +01:00 committed by Matt Keeler
parent c8a1acd508
commit 2aa516fd64
2 changed files with 16 additions and 1 deletions

View File

@ -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
}

View File

@ -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")