Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

crypt: make rclone dedupe work through crypt

Nick Craig-Wood7981e450a4c4
diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go
index d2cc796d0..4a798e6ec 100644
--- a/backend/crypt/crypt.go
+++ b/backend/crypt/crypt.go
@@ -202,6 +202,7 @@ type Options struct {
// Fs represents a wrapped fs.Fs
type Fs struct {
fs.Fs
+ wrapper fs.Fs
name string
root string
opt Options
@@ -544,6 +545,16 @@ func (f *Fs) UnWrap() fs.Fs {
return f.Fs
}
+// WrapFs returns the Fs that is wrapping this Fs
+func (f *Fs) WrapFs() fs.Fs {
+ return f.wrapper
+}
+
+// SetWrapper sets the Fs that is wrapping this Fs
+func (f *Fs) SetWrapper(wrapper fs.Fs) {
+ f.wrapper = wrapper
+}
+
// EncryptFileName returns an encrypted file name
func (f *Fs) EncryptFileName(fileName string) string {
return f.cipher.EncryptFileName(fileName)
@@ -616,6 +627,29 @@ func (f *Fs) ComputeHash(o *Object, src fs.Object, hashType hash.Type) (hashStr
return m.Sums()[hashType], nil
}
+// MergeDirs merges the contents of all the directories passed
+// in into the first one and rmdirs the other directories.
+func (f *Fs) MergeDirs(dirs []fs.Directory) error {
+ do := f.Fs.Features().MergeDirs
+ if do == nil {
+ return errors.New("MergeDirs not supported")
+ }
+ out := make([]fs.Directory, len(dirs))
+ for i, dir := range dirs {
+ out[i] = fs.NewDirCopy(dir).SetRemote(f.cipher.EncryptDirName(dir.Remote()))
+ }
+ return do(out)
+}
+
+// DirCacheFlush resets the directory cache - used in testing
+// as an optional interface
+func (f *Fs) DirCacheFlush() {
+ do := f.Fs.Features().DirCacheFlush
+ if do != nil {
+ do()
+ }
+}
+
// Object describes a wrapped for being read from the Fs
//
// This decrypts the remote name and decrypts the data