Skip to content

Commit 1ab96d5

Browse files
committed
Fix #11: Gracefully handle invalid dates
1 parent 12190d2 commit 1ab96d5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

rotate_backups/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,13 @@ def collect_backups(self, location):
565565
elif self.include_list and not any(fnmatch.fnmatch(entry, p) for p in self.include_list):
566566
logger.verbose("Excluded %s (it didn't match the include list).", entry)
567567
else:
568-
backups.append(Backup(
569-
pathname=os.path.join(location.directory, entry),
570-
timestamp=datetime.datetime(*(int(group, 10) for group in match.groups('0'))),
571-
))
568+
try:
569+
backups.append(Backup(
570+
pathname=os.path.join(location.directory, entry),
571+
timestamp=datetime.datetime(*(int(group, 10) for group in match.groups('0'))),
572+
))
573+
except ValueError as e:
574+
logger.notice("Ignoring %s due to invalid date (%s).", entry, e)
572575
else:
573576
logger.debug("Failed to match time stamp in filename: %s", entry)
574577
if backups:

0 commit comments

Comments
 (0)