MCPcopy
hub / github.com/rclone/rclone / tryRename

Method tryRename

fs/sync/sync.go:883–914  ·  view source on GitHub ↗

tryRename renames an src object when doing track renames if possible, it returns true if the object was renamed.

(src fs.Object)

Source from the content-addressed store, hash-verified

881// tryRename renames an src object when doing track renames if
882// possible, it returns true if the object was renamed.
883func (s *syncCopyMove) tryRename(src fs.Object) bool {
884 // Calculate the hash of the src object
885 hash := s.renameID(src, s.trackRenamesStrategy, fs.GetModifyWindow(s.ctx, s.fsrc, s.fdst))
886
887 if hash == "" {
888 return false
889 }
890
891 // Get a match on fdst
892 dst := s.popRenameMap(hash, src)
893 if dst == nil {
894 return false
895 }
896
897 // Find dst object we are about to overwrite if it exists
898 dstOverwritten, _ := s.fdst.NewObject(s.ctx, src.Remote())
899
900 // Rename dst to have name src.Remote()
901 _, err := operations.Move(s.ctx, s.fdst, dstOverwritten, src.Remote(), dst)
902 if err != nil {
903 fs.Debugf(src, "Failed to rename to %q: %v", dst.Remote(), err)
904 return false
905 }
906
907 // remove file from dstFiles if present
908 s.dstFilesMu.Lock()
909 delete(s.dstFiles, dst.Remote())
910 s.dstFilesMu.Unlock()
911
912 fs.Infof(src, "Renamed from %q", dst.Remote())
913 return true
914}
915
916// Syncs fsrc into fdst
917//

Callers 1

pairRenamerMethod · 0.95

Calls 10

renameIDMethod · 0.95
popRenameMapMethod · 0.95
GetModifyWindowFunction · 0.92
MoveFunction · 0.92
DebugfFunction · 0.92
InfofFunction · 0.92
NewObjectMethod · 0.65
RemoteMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected