bpo-30989: Sort in TimedRotatingFileHandler only when needed. (GH-2812) (GH-4466)

TimedRotatingFileHandler.getFilesToDelete() now sorts only when needed.
(cherry picked from commit afad147b59)
This commit is contained in:
Miss Islington (bot) 2017-11-19 10:43:49 -08:00 committed by Vinay Sajip
parent 80baec58f5
commit 65dffe58dd

View file

@ -356,10 +356,10 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
suffix = fileName[plen:] suffix = fileName[plen:]
if self.extMatch.match(suffix): if self.extMatch.match(suffix):
result.append(os.path.join(dirName, fileName)) result.append(os.path.join(dirName, fileName))
result.sort()
if len(result) < self.backupCount: if len(result) < self.backupCount:
result = [] result = []
else: else:
result.sort()
result = result[:len(result) - self.backupCount] result = result[:len(result) - self.backupCount]
return result return result