From a31f2907f05bf7fea9a4e341eb3c6f44ca815cd1 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 29 Aug 2021 18:46:28 -0700 Subject: [PATCH] cloud drive: filer.remote.sync supports remove folder --- weed/command/filer_remote_sync.go | 4 ++++ weed/remote_storage/azure/azure_storage_client.go | 4 ++++ weed/remote_storage/gcs/gcs_storage_client.go | 4 ++++ weed/remote_storage/hdfs/hdfs_storage_client.go | 4 ++++ weed/remote_storage/remote_storage.go | 1 + weed/remote_storage/s3/s3_storage_client.go | 4 ++++ 6 files changed, 21 insertions(+) diff --git a/weed/command/filer_remote_sync.go b/weed/command/filer_remote_sync.go index 48713093e..8d2719660 100644 --- a/weed/command/filer_remote_sync.go +++ b/weed/command/filer_remote_sync.go @@ -164,6 +164,10 @@ func followUpdatesAndUploadToRemote(option *RemoteSyncOptions, filerSource *sour if message.OldEntry != nil && message.NewEntry == nil { glog.V(2).Infof("delete: %+v", resp) dest := toRemoteStorageLocation(util.FullPath(mountedDir), util.NewFullPath(resp.Directory, message.OldEntry.Name), remoteStorageMountLocation) + if message.OldEntry.IsDirectory { + glog.V(0).Infof("rmdir %s", remote_storage.FormatLocation(dest)) + return client.RemoveDirectory(dest) + } glog.V(0).Infof("delete %s", remote_storage.FormatLocation(dest)) return client.DeleteFile(dest) } diff --git a/weed/remote_storage/azure/azure_storage_client.go b/weed/remote_storage/azure/azure_storage_client.go index 21b8606c3..3982750f3 100644 --- a/weed/remote_storage/azure/azure_storage_client.go +++ b/weed/remote_storage/azure/azure_storage_client.go @@ -128,6 +128,10 @@ func (az *azureRemoteStorageClient) WriteDirectory(loc *remote_pb.RemoteStorageL return nil } +func (az *azureRemoteStorageClient) RemoveDirectory(loc *remote_pb.RemoteStorageLocation) (err error) { + return nil +} + func (az *azureRemoteStorageClient) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error) { key := loc.Path[1:] diff --git a/weed/remote_storage/gcs/gcs_storage_client.go b/weed/remote_storage/gcs/gcs_storage_client.go index 828d62978..683b90086 100644 --- a/weed/remote_storage/gcs/gcs_storage_client.go +++ b/weed/remote_storage/gcs/gcs_storage_client.go @@ -111,6 +111,10 @@ func (gcs *gcsRemoteStorageClient) WriteDirectory(loc *remote_pb.RemoteStorageLo return nil } +func (gcs *gcsRemoteStorageClient) RemoveDirectory(loc *remote_pb.RemoteStorageLocation) (err error) { + return nil +} + func (gcs *gcsRemoteStorageClient) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error) { key := loc.Path[1:] diff --git a/weed/remote_storage/hdfs/hdfs_storage_client.go b/weed/remote_storage/hdfs/hdfs_storage_client.go index 0c5f5a45d..e4d7dcb44 100644 --- a/weed/remote_storage/hdfs/hdfs_storage_client.go +++ b/weed/remote_storage/hdfs/hdfs_storage_client.go @@ -104,6 +104,10 @@ func (c *hdfsRemoteStorageClient) WriteDirectory(loc *remote_pb.RemoteStorageLoc return c.client.MkdirAll(loc.Path, os.FileMode(entry.Attributes.FileMode)) } +func (c *hdfsRemoteStorageClient) RemoveDirectory(loc *remote_pb.RemoteStorageLocation) (err error) { + return c.client.RemoveAll(loc.Path) +} + func (c *hdfsRemoteStorageClient) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error) { dirname := path.Dir(loc.Path) diff --git a/weed/remote_storage/remote_storage.go b/weed/remote_storage/remote_storage.go index a4caef0d4..af65ca677 100644 --- a/weed/remote_storage/remote_storage.go +++ b/weed/remote_storage/remote_storage.go @@ -65,6 +65,7 @@ type RemoteStorageClient interface { Traverse(loc *remote_pb.RemoteStorageLocation, visitFn VisitFunc) error ReadFile(loc *remote_pb.RemoteStorageLocation, offset int64, size int64) (data []byte, err error) WriteDirectory(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry) (err error) + RemoveDirectory(loc *remote_pb.RemoteStorageLocation) (err error) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error) UpdateFileMetadata(loc *remote_pb.RemoteStorageLocation, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) (err error) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) diff --git a/weed/remote_storage/s3/s3_storage_client.go b/weed/remote_storage/s3/s3_storage_client.go index a210683aa..2756c91a8 100644 --- a/weed/remote_storage/s3/s3_storage_client.go +++ b/weed/remote_storage/s3/s3_storage_client.go @@ -124,6 +124,10 @@ func (s *s3RemoteStorageClient) WriteDirectory(loc *remote_pb.RemoteStorageLocat return nil } +func (s *s3RemoteStorageClient) RemoveDirectory(loc *remote_pb.RemoteStorageLocation) (err error) { + return nil +} + func (s *s3RemoteStorageClient) WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error) { fileSize := int64(filer.FileSize(entry))