From eaf2b3c0ea0752a741d52efa5e48fef2e97c1955 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Tue, 22 Jun 2021 07:36:50 +0300 Subject: [PATCH] Fix setting directories' mtime in rsync --- spqr/curateipsum/fs.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spqr/curateipsum/fs.py b/spqr/curateipsum/fs.py index e9cce41..b7406bd 100644 --- a/spqr/curateipsum/fs.py +++ b/spqr/curateipsum/fs.py @@ -210,6 +210,23 @@ def rsync(src_dir, dst_dir, dry_run=False): _lg.info("creating %s", rel_path) copy_direntry(src_entry, dst_path) + # restore dir mtimes in dst, updated by updating files + for src_entry in scantree(src_root_abs, dir_first=True): + if not src_entry.is_dir(): + continue + rel_path = src_entry.path[len(src_root_abs) + 1 :] + dst_path = os.path.join(dst_root_abs, rel_path) + src_stat = src_entry.stat(follow_symlinks=False) + os.utime(dst_path, + (src_stat.st_atime, src_stat.st_mtime), + follow_symlinks=False) + + # restore dst_root dir mtime + src_root_stat = os.lstat(src_root_abs) + os.utime(dst_root_abs, + (src_root_stat.st_atime, src_root_stat.st_mtime), + follow_symlinks=False) + def _hardlink_dir_ext(src, dst) -> bool: """