From ca017980a3e997cb381fca528c7c2bc05a0f9905 Mon Sep 17 00:00:00 2001 From: Too Much IO Date: Sun, 30 Oct 2016 21:02:38 +1100 Subject: [PATCH] Add support for server side move operations Depends on pull request at https://github.com/ncw/go-acd/pull/1 --- amazonclouddrive/amazonclouddrive.go | 47 +++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/amazonclouddrive/amazonclouddrive.go b/amazonclouddrive/amazonclouddrive.go index cc6cc287f..2d9d86963 100644 --- a/amazonclouddrive/amazonclouddrive.go +++ b/amazonclouddrive/amazonclouddrive.go @@ -674,6 +674,51 @@ func (f *Fs) Hashes() fs.HashSet { return fs.HashSet(fs.HashMD5) } +func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) { + srcObj, ok := src.(*Object) + if !ok { + fs.Debug(src, "Can't move - not same remote type") + return nil, fs.ErrorCantMove + } + + // Temporary Object under construction + dstObj := &Object{ + fs: f, + remote: remote, + } + + var err error + _, directoryID, err := f.dirCache.FindPath(remote, false) + if err != nil { + return nil, err + } + + var info *acd.Node + var resp *http.Response + if directoryID == srcObj.info.Parents[0] { + // Do the rename + err = f.pacer.Call(func() (bool, error) { + info, resp, err = srcObj.info.Rename(remote) + return srcObj.fs.shouldRetry(resp, err) + }) + if err != nil { + return nil, err + } + } else { + // Do the move + err = f.pacer.Call(func() (bool, error) { + info, resp, err = srcObj.info.Move(directoryID) + return srcObj.fs.shouldRetry(resp, err) + }) + if err != nil { + return nil, err + } + } + + dstObj.info = info + return dstObj, nil +} + // Copy src to this remote using server side copy operations. // // This is stored with the remote path given @@ -881,7 +926,7 @@ var ( _ fs.Fs = (*Fs)(nil) _ fs.Purger = (*Fs)(nil) // _ fs.Copier = (*Fs)(nil) - // _ fs.Mover = (*Fs)(nil) + _ fs.Mover = (*Fs)(nil) // _ fs.DirMover = (*Fs)(nil) _ fs.Object = (*Object)(nil) _ fs.MimeTyper = &Object{}