crypt: Implement DirMover

This commit is contained in:
Nick Craig-Wood 2016-08-23 17:43:43 +01:00
parent a54806e5c1
commit 73cd1f4e88
1 changed files with 28 additions and 7 deletions

View File

@ -99,7 +99,7 @@ type Fs struct {
// String returns a description of the FS
func (f *Fs) String() string {
return fmt.Sprintf("%s with cipher", f.Fs.String())
return fmt.Sprintf("Encrypted %s", f.Fs.String())
}
// List the Fs into a channel
@ -193,7 +193,7 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) {
}
o, ok := src.(*Object)
if !ok {
return nil, fs.ErrorCantCopy
return nil, fs.ErrorCantMove
}
oResult, err := do.Move(o.Object, f.cipher.EncryptFileName(remote))
if err != nil {
@ -202,6 +202,27 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) {
return f.newObject(oResult), nil
}
// DirMove moves src to this remote using server side move
// operations.
//
// Will only be called if src.Fs().Name() == f.Name()
//
// If it isn't possible then return fs.ErrorCantDirMove
//
// If destination exists then return fs.ErrorDirExists
func (f *Fs) DirMove(src fs.Fs) error {
do, ok := f.Fs.(fs.DirMover)
if !ok {
return fs.ErrorCantDirMove
}
srcFs, ok := src.(*Fs)
if !ok {
fs.Debug(srcFs, "Can't move directory - not same remote type")
return fs.ErrorCantDirMove
}
return do.DirMove(srcFs.Fs)
}
// UnWrap returns the Fs that this Fs is wrapping
func (f *Fs) UnWrap() fs.Fs {
return f.Fs
@ -396,11 +417,11 @@ func (lo *ListOpts) IncludeDirectory(remote string) bool {
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
// _ fs.DirMover = (*Fs)(nil)
_ fs.Fs = (*Fs)(nil)
_ fs.Purger = (*Fs)(nil)
_ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil)
// _ fs.PutUncheckeder = (*Fs)(nil)
_ fs.UnWrapper = (*Fs)(nil)
_ fs.ObjectInfo = (*ObjectInfo)(nil)