diff --git a/client/driver/logging/rotator.go b/client/driver/logging/rotator.go index 93a4be4f0..5fbe218b3 100644 --- a/client/driver/logging/rotator.go +++ b/client/driver/logging/rotator.go @@ -238,11 +238,16 @@ func (f *FileRotator) purgeOldFiles() { } } + // Not continuing to delete files if the number of files is not more + // than MaxFiles + if len(fIndexes) <= f.MaxFiles { + continue + } + // Sorting the file indexes so that we can purge the older files and keep // only the number of files as configured by the user sort.Sort(sort.IntSlice(fIndexes)) - var toDelete []int - toDelete = fIndexes[0 : len(fIndexes)-f.MaxFiles] + toDelete := fIndexes[0 : len(fIndexes)-f.MaxFiles] for _, fIndex := range toDelete { fname := filepath.Join(f.path, fmt.Sprintf("%s.%d", f.baseFileName, fIndex)) os.RemoveAll(fname)