1313import subprocess
1414import threading
1515import time
16+ from datetime import datetime
1617from enum import Enum
1718from pathlib import Path
1819from typing import Awaitable , Callable , List , NamedTuple
@@ -63,6 +64,7 @@ def __init__(
6364 remove_files : bool = False ,
6465 required_substrings_for_removal : List [str ] = [],
6566 notify : bool = True ,
67+ end_time : datetime | None = None ,
6668 ):
6769 super ().__init__ ()
6870 self ._basepath = basepath_local .absolute ()
@@ -76,6 +78,9 @@ def __init__(
7678 self ._server_url = server_url
7779 self ._notify = notify
7880 self ._finalised = False
81+ self ._end_time = end_time
82+
83+ self ._skipped_files : List [Path ] = []
7984
8085 # Set rsync destination
8186 if local :
@@ -214,6 +219,10 @@ def enqueue(self, file_path: Path):
214219 absolute_path = self ._basepath / file_path
215220 self .queue .put (absolute_path )
216221
222+ def flush_skipped (self ):
223+ for f in self ._skipped_files :
224+ self .queue .put (f )
225+
217226 def _process (self ):
218227 logger .info ("RSync thread starting" )
219228 files_to_transfer : list [Path ]
@@ -304,14 +313,23 @@ def _fake_transfer(self, files: list[Path]) -> bool:
304313
305314 return True
306315
307- def _transfer (self , files : list [Path ]) -> bool :
316+ def _transfer (self , infiles : list [Path ]) -> bool :
308317 """
309318 Transfer files via an rsync sub-process, and parses the rsync stdout to verify
310319 the success of the transfer.
311320 """
312321
313322 # Set up initial variables
314- files = [f for f in files if f .is_file ()]
323+ if self ._end_time :
324+ files = [
325+ f
326+ for f in infiles
327+ if f .is_file () and f .stat ().st_ctime < self ._end_time .timestamp ()
328+ ]
329+ self ._skipped_files .extend (set (infiles ).difference (set (files )))
330+ else :
331+ files = [f for f in infiles if f .is_file ()]
332+
315333 previously_transferred = self ._files_transferred
316334 transfer_success : set [Path ] = set ()
317335 successful_updates : list [RSyncerUpdate ] = []
0 commit comments