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.
This commit is contained in:
ll3006 2025-02-07 14:23:28 +01:00 committed by Nick Craig-Wood
parent 2ff8aa1c20
commit c1b414e2cf
1 changed files with 8 additions and 14 deletions

View File

@ -1109,23 +1109,17 @@ func (s *syncCopyMove) copyDirMetadata(ctx context.Context, f fs.Fs, dst fs.Dire
if !s.setDirModTimeAfter && equal { if !s.setDirModTimeAfter && equal {
return nil return nil
} }
if s.setDirModTimeAfter && equal {
newDst = dst newDst = dst
} else if s.copyEmptySrcDirs { if !equal {
if s.setDirMetadata { if s.setDirMetadata && s.copyEmptySrcDirs {
newDst, err = operations.CopyDirMetadata(ctx, f, dst, dir, src) newDst, err = operations.CopyDirMetadata(ctx, f, dst, dir, src)
} else if s.setDirModTime { } else if dst == nil && s.setDirModTime && s.copyEmptySrcDirs {
if dst == nil {
newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx)) newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx))
} else { } 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)) newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx))
} }
} else if dst == nil {
// Create the directory if it doesn't exist
err = operations.Mkdir(ctx, f, dir)
}
} else {
newDst = dst
} }
// If we need to set modtime after and we created a dir, then save it for later // If we need to set modtime after and we created a dir, then save it for later
if s.setDirModTime && s.setDirModTimeAfter && err == nil { if s.setDirModTime && s.setDirModTimeAfter && err == nil {