From c1b414e2cf6d63937caf102a49f43cc3637e9c4f Mon Sep 17 00:00:00 2001 From: ll3006 Date: Fri, 7 Feb 2025 14:23:28 +0100 Subject: [PATCH] sync: copy dir modtimes even when copyEmptySrcDirs is false - fixes #8317 Before, after a sync, only file modtimes were updated when not using --copy-empty-src-dirs. This ensures modtimes are updated to match the source folder, regardless of copyEmptySrcDir. The flag --no-update-dir-modtime (which previously did nothing) will disable this. --- fs/sync/sync.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/fs/sync/sync.go b/fs/sync/sync.go index 7feedfcd7..e30c86ed2 100644 --- a/fs/sync/sync.go +++ b/fs/sync/sync.go @@ -1109,23 +1109,17 @@ func (s *syncCopyMove) copyDirMetadata(ctx context.Context, f fs.Fs, dst fs.Dire if !s.setDirModTimeAfter && equal { return nil } - if s.setDirModTimeAfter && equal { - newDst = dst - } else if s.copyEmptySrcDirs { - if s.setDirMetadata { + newDst = dst + if !equal { + if s.setDirMetadata && s.copyEmptySrcDirs { newDst, err = operations.CopyDirMetadata(ctx, f, dst, dir, src) - } else if s.setDirModTime { - if dst == nil { - newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx)) - } else { - newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx)) - } - } else if dst == nil { - // Create the directory if it doesn't exist + } else if dst == nil && s.setDirModTime && s.copyEmptySrcDirs { + newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx)) + } else if dst == nil && s.copyEmptySrcDirs { err = operations.Mkdir(ctx, f, dir) + } else if dst != nil && s.setDirModTime { + newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx)) } - } else { - newDst = dst } // If we need to set modtime after and we created a dir, then save it for later if s.setDirModTime && s.setDirModTimeAfter && err == nil {