tryRename renames an src object when doing track renames if possible, it returns true if the object was renamed.
(src fs.Object)
| 881 | // tryRename renames an src object when doing track renames if |
| 882 | // possible, it returns true if the object was renamed. |
| 883 | func (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 | // |
no test coverage detected