@@ -365,32 +365,37 @@ def getFilesToDelete(self):
365
365
dirName , baseName = os .path .split (self .baseFilename )
366
366
fileNames = os .listdir (dirName )
367
367
result = []
368
- # See bpo-44753: Don't use the extension when computing the prefix.
369
- n , e = os .path .splitext (baseName )
370
- prefix = n + '.'
371
- plen = len (prefix )
372
- for fileName in fileNames :
373
- if self .namer is None :
374
- # Our files will always start with baseName
375
- if not fileName .startswith (baseName ):
376
- continue
377
- else :
368
+ if self .namer is None :
369
+ prefix = baseName + '.'
370
+ plen = len (prefix )
371
+ for fileName in fileNames :
372
+ if fileName [:plen ] == prefix :
373
+ suffix = fileName [plen :]
374
+ if self .extMatch .match (suffix ):
375
+ result .append (os .path .join (dirName , fileName ))
376
+ else :
377
+ # See bpo-44753: Don't use the extension when computing the prefix.
378
+ n , e = os .path .splitext (baseName )
379
+ prefix = n + '.'
380
+ plen = len (prefix )
381
+ for fileName in fileNames :
378
382
# Our files could be just about anything after custom naming, but
379
383
# likely candidates are of the form
380
384
# foo.log.DATETIME_SUFFIX or foo.DATETIME_SUFFIX.log
381
385
if (not fileName .startswith (baseName ) and fileName .endswith (e ) and
382
386
len (fileName ) > (plen + 1 ) and not fileName [plen + 1 ].isdigit ()):
383
387
continue
384
388
385
- if fileName [:plen ] == prefix :
386
- suffix = fileName [plen :]
387
- # See bpo-45628: The date/time suffix could be anywhere in the
388
- # filename
389
- parts = suffix .split ('.' )
390
- for part in parts :
391
- if self .extMatch .match (part ):
392
- result .append (os .path .join (dirName , fileName ))
393
- break
389
+ if fileName [:plen ] == prefix :
390
+ suffix = fileName [plen :]
391
+ # See bpo-45628: The date/time suffix could be anywhere in the
392
+ # filename
393
+
394
+ parts = suffix .split ('.' )
395
+ for part in parts :
396
+ if self .extMatch .match (part ):
397
+ result .append (os .path .join (dirName , fileName ))
398
+ break
394
399
if len (result ) < self .backupCount :
395
400
result = []
396
401
else :
0 commit comments