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

fs: add Optional ID() method to Object and implement it in backends

Nick Craig-Wood826975c34128
diff --git a/backend/amazonclouddrive/amazonclouddrive.go b/backend/amazonclouddrive/amazonclouddrive.go
index f1aec3028..35008430f 100644
--- a/backend/amazonclouddrive/amazonclouddrive.go
+++ b/backend/amazonclouddrive/amazonclouddrive.go
@@ -1315,6 +1315,14 @@ func (f *Fs) changeNotifyRunner(notifyFunc func(string, fs.EntryType), checkpoin
return checkpoint
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ if o.info.Id == nil {
+ return ""
+ }
+ return *o.info.Id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1326,4 +1334,5 @@ var (
_ fs.ChangeNotifier = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
+ _ fs.IDer = &Object{}
)
diff --git a/backend/b2/b2.go b/backend/b2/b2.go
index cf2ac601d..a876d5083 100644
--- a/backend/b2/b2.go
+++ b/backend/b2/b2.go
@@ -1422,6 +1422,11 @@ func (o *Object) MimeType() string {
return o.mimeType
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = &Fs{}
@@ -1431,4 +1436,5 @@ var (
_ fs.ListRer = &Fs{}
_ fs.Object = &Object{}
_ fs.MimeTyper = &Object{}
+ _ fs.IDer = &Object{}
)
diff --git a/backend/box/box.go b/backend/box/box.go
index 47086a3d4..fde034ac7 100644
--- a/backend/box/box.go
+++ b/backend/box/box.go
@@ -1048,6 +1048,11 @@ func (o *Object) Remove() error {
return o.fs.deleteObject(o.id)
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1058,4 +1063,5 @@ var (
_ fs.DirMover = (*Fs)(nil)
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
+ _ fs.IDer = (*Object)(nil)
)
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index e80364868..b1ff8cac1 100644
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -1678,6 +1678,11 @@ func (o *Object) MimeType() string {
return o.mimeType
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1695,4 +1700,5 @@ var (
_ fs.Abouter = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = (*Object)(nil)
+ _ fs.IDer = (*Object)(nil)
)
diff --git a/backend/mega/mega.go b/backend/mega/mega.go
index fc7be7344..5dbb03030 100644
--- a/backend/mega/mega.go
+++ b/backend/mega/mega.go
@@ -1110,6 +1110,11 @@ func (o *Object) Remove() error {
return nil
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.info.GetHash()
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1122,4 +1127,5 @@ var (
_ fs.MergeDirser = (*Fs)(nil)
_ fs.Abouter = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
+ _ fs.IDer = (*Object)(nil)
)
diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go
index bcea113ea..09399d603 100644
--- a/backend/onedrive/onedrive.go
+++ b/backend/onedrive/onedrive.go
@@ -1302,6 +1302,11 @@ func (o *Object) MimeType() string {
return o.mimeType
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1313,4 +1318,5 @@ var (
_ fs.Abouter = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
_ fs.MimeTyper = &Object{}
+ _ fs.IDer = &Object{}
)
diff --git a/backend/opendrive/opendrive.go b/backend/opendrive/opendrive.go
index c461f4aa8..9a2f9aeb0 100644
--- a/backend/opendrive/opendrive.go
+++ b/backend/opendrive/opendrive.go
@@ -1086,6 +1086,11 @@ func (o *Object) readMetaData() (err error) {
return nil
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1095,4 +1100,5 @@ var (
_ fs.DirMover = (*Fs)(nil)
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
+ _ fs.IDer = (*Object)(nil)
)
diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go
index 936842cec..741109a3c 100644
--- a/backend/pcloud/pcloud.go
+++ b/backend/pcloud/pcloud.go
@@ -1118,6 +1118,11 @@ func (o *Object) Remove() error {
})
}
+// ID returns the ID of the Object if known, or "" if not
+func (o *Object) ID() string {
+ return o.id
+}
+
// Check the interfaces are satisfied
var (
_ fs.Fs = (*Fs)(nil)
@@ -1129,4 +1134,5 @@ var (
_ fs.DirCacheFlusher = (*Fs)(nil)
_ fs.Abouter = (*Fs)(nil)
_ fs.Object = (*Object)(nil)
+ _ fs.IDer = (*Object)(nil)
)
diff --git a/fs/fs.go b/fs/fs.go
index 7a67faae6..9325a6b85 100644
--- a/fs/fs.go
+++ b/fs/fs.go
@@ -246,6 +246,12 @@ type MimeTyper interface {
MimeType() string
}
+// IDer is an optional interface for Object
+type IDer interface {
+ // ID returns the ID of the Object if known, or "" if not
+ ID() string
+}
+
// ObjectUnWrapper is an optional interface for Object
type ObjectUnWrapper interface {
// UnWrap returns the Object that this Object is wrapping or