Skip to content

Commit c1b414e

Browse files
ll3006ncw
authored andcommitted
sync: copy dir modtimes even when copyEmptySrcDirs is false - fixes rclone#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.
1 parent 2ff8aa1 commit c1b414e

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

fs/sync/sync.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,23 +1109,17 @@ func (s *syncCopyMove) copyDirMetadata(ctx context.Context, f fs.Fs, dst fs.Dire
11091109
if !s.setDirModTimeAfter && equal {
11101110
return nil
11111111
}
1112-
if s.setDirModTimeAfter && equal {
1113-
newDst = dst
1114-
} else if s.copyEmptySrcDirs {
1115-
if s.setDirMetadata {
1112+
newDst = dst
1113+
if !equal {
1114+
if s.setDirMetadata && s.copyEmptySrcDirs {
11161115
newDst, err = operations.CopyDirMetadata(ctx, f, dst, dir, src)
1117-
} else if s.setDirModTime {
1118-
if dst == nil {
1119-
newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx))
1120-
} else {
1121-
newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx))
1122-
}
1123-
} else if dst == nil {
1124-
// Create the directory if it doesn't exist
1116+
} else if dst == nil && s.setDirModTime && s.copyEmptySrcDirs {
1117+
newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx))
1118+
} else if dst == nil && s.copyEmptySrcDirs {
11251119
err = operations.Mkdir(ctx, f, dir)
1120+
} else if dst != nil && s.setDirModTime {
1121+
newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx))
11261122
}
1127-
} else {
1128-
newDst = dst
11291123
}
11301124
// If we need to set modtime after and we created a dir, then save it for later
11311125
if s.setDirModTime && s.setDirModTimeAfter && err == nil {

0 commit comments

Comments
 (0)