Merge pull request #1006 from hashicorp/guard-purge-files

Not deleting files if the number of files is less than max files
This commit is contained in:
Diptanu Choudhury 2016-03-29 17:31:35 -07:00
commit 6bf0c8026a

View file

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