File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -704,7 +704,7 @@ def match_to_datetime(self, match):
704
704
except ValueError :
705
705
timestamp = None
706
706
if timestamp is None :
707
- logger . notice ( "Ignoring %s due to invalid date (%s)." , value , match . group () )
707
+ raise ValueError ( "%r could not be extracted as unix timestamp" )
708
708
else :
709
709
logger .verbose ("Extracted timestamp %r from %r" , timestamp , value )
710
710
return timestamp
Original file line number Diff line number Diff line change @@ -145,6 +145,21 @@ def test_argument_validation(self):
145
145
returncode , output = run_cli (main , '-n' , '/root' )
146
146
assert returncode != 0
147
147
148
+ def test_timestamp_dates (self ):
149
+ """Make sure filenames with unix timestamps don't cause an exception."""
150
+ with TemporaryDirectory (prefix = 'rotate-backups-' , suffix = '-test-suite' ) as root :
151
+ file_with_valid_date = os .path .join (root , 'snapshot-1612396800061.tar.gz' )
152
+ file_with_invalid_date = os .path .join (root , 'snapshot-1807311501019237.tar.gz' )
153
+ for filename in file_with_valid_date , file_with_invalid_date :
154
+ touch (filename )
155
+ program = RotateBackups (
156
+ rotation_scheme = dict (monthly = 'always' ),
157
+ timestamp_pattern = r"-(?P<unixtime>\d+)\.tar\.gz"
158
+ )
159
+ backups = program .collect_backups (root )
160
+ assert len (backups ) == 1
161
+ assert backups [0 ].pathname == file_with_valid_date
162
+
148
163
def test_invalid_dates (self ):
149
164
"""Make sure filenames with invalid dates don't cause an exception."""
150
165
with TemporaryDirectory (prefix = 'rotate-backups-' , suffix = '-test-suite' ) as root :
You can’t perform that action at this time.
0 commit comments