MCPcopy
hub / github.com/rclone/rclone / copyDirMetadata

Method copyDirMetadata

fs/sync/sync.go:1106–1161  ·  view source on GitHub ↗

copyDirMetadata copies the src directory modTime or Metadata to dst or f if nil. If dst is nil then it uses dir as the name of the new directory. It returns the destination directory if possible. Note that this may be nil.

(ctx context.Context, f fs.Fs, dst fs.Directory, dir string, src fs.Directory)

Source from the content-addressed store, hash-verified

1104// It returns the destination directory if possible. Note that this may
1105// be nil.
1106func (s *syncCopyMove) copyDirMetadata(ctx context.Context, f fs.Fs, dst fs.Directory, dir string, src fs.Directory) (newDst fs.Directory) {
1107 var err error
1108 if dst != nil && src.Remote() == dst.Remote() && operations.OverlappingFilterCheck(ctx, s.fdst, s.fsrc) {
1109 return nil // src and dst can be the same in convmv
1110 }
1111 equal := operations.DirsEqual(ctx, src, dst, operations.DirsEqualOpt{ModifyWindow: s.modifyWindow, SetDirModtime: s.setDirModTime, SetDirMetadata: s.setDirMetadata})
1112 if !s.setDirModTimeAfter && equal {
1113 return nil
1114 }
1115 newDst = dst
1116 if !equal {
1117 if s.setDirMetadata && s.copyEmptySrcDirs {
1118 newDst, err = operations.CopyDirMetadata(ctx, f, dst, dir, src)
1119 } else if dst == nil && s.setDirModTime && s.copyEmptySrcDirs {
1120 newDst, err = operations.MkdirModTime(ctx, f, dir, src.ModTime(ctx))
1121 } else if dst == nil && s.copyEmptySrcDirs {
1122 err = operations.Mkdir(ctx, f, dir)
1123 } else if dst != nil && s.setDirModTime {
1124 newDst, err = operations.SetDirModTime(ctx, f, dst, dir, src.ModTime(ctx))
1125 }
1126 }
1127 if transform.Transforming(ctx) && newDst != nil && src.Remote() != newDst.Remote() {
1128 s.markParentNotEmpty(src)
1129 }
1130 // If we need to set modtime after and we created a dir, then save it for later
1131 if s.setDirModTime && s.setDirModTimeAfter && err == nil {
1132 if newDst != nil {
1133 dir = newDst.Remote()
1134 }
1135 level := strings.Count(dir, "/") + 1
1136 // The root directory "" is at the top level
1137 if dir == "" {
1138 level = 0
1139 }
1140 s.setDirModTimeMu.Lock()
1141 // Keep track of the maximum level inserted
1142 if level > s.setDirModTimesMaxLevel {
1143 s.setDirModTimesMaxLevel = level
1144 }
1145 set := setDirModTime{
1146 src: src,
1147 dst: newDst,
1148 dir: dir,
1149 modTime: src.ModTime(ctx),
1150 level: level,
1151 }
1152 s.setDirModTimes = append(s.setDirModTimes, set)
1153 s.setDirModTimeMu.Unlock()
1154 fs.Debugf(nil, "Added delayed dir = %q, newDst=%v", dir, newDst)
1155 }
1156 s.processError(err)
1157 if err != nil {
1158 return nil
1159 }
1160 return newDst
1161}
1162
1163// Set the modtimes for directories

Callers 2

SrcOnlyMethod · 0.95
MatchMethod · 0.95

Calls 15

markParentNotEmptyMethod · 0.95
processErrorMethod · 0.95
OverlappingFilterCheckFunction · 0.92
DirsEqualFunction · 0.92
CopyDirMetadataFunction · 0.92
MkdirModTimeFunction · 0.92
MkdirFunction · 0.92
SetDirModTimeFunction · 0.92
TransformingFunction · 0.92
DebugfFunction · 0.92
RemoteMethod · 0.65
ModTimeMethod · 0.65

Tested by

no test coverage detected