SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
Prevent bucket renaming in filer, fuse mount, and S3 (#8048)
Chris Lu796a911cb3e5
diff --git a/weed/filer/filer_buckets.go b/weed/filer/filer_buckets.goindex e9cb3547ec..4b6c06d356 100644--- a/weed/filer/filer_buckets.go+++ b/weed/filer/filer_buckets.go@@ -4,7 +4,7 @@ import ("strings")-func (f *Filer) isBucket(entry *Entry) bool {+func (f *Filer) IsBucket(entry *Entry) bool {if !entry.IsDirectory() {return false}diff --git a/weed/filer/filer_delete_entry.go b/weed/filer/filer_delete_entry.goindex 8b90f8c00b..77d9e34a7d 100644--- a/weed/filer/filer_delete_entry.go+++ b/weed/filer/filer_delete_entry.go@@ -29,7 +29,7 @@ func (f *Filer) DeleteEntryMetaAndData(ctx context.Context, p util.FullPath, isRif ifNotModifiedAfter > 0 && entry.Attr.Mtime.Unix() > ifNotModifiedAfter {return nil}- isDeleteCollection := f.isBucket(entry)+ isDeleteCollection := f.IsBucket(entry)if entry.IsDirectory() {// delete the folder children, not including the folder itselferr = f.doBatchDeleteFolderMetaAndData(ctx, entry, isRecursive, ignoreRecursiveError, shouldDeleteChunks && !isDeleteCollection, isDeleteCollection, isFromOtherCluster, signatures, func(hardLinkIds []HardLinkId) error {@@ -90,7 +90,7 @@ func (f *Filer) doBatchDeleteFolderMetaAndData(ctx context.Context, entry *Entryfor _, sub := range entries {lastFileName = sub.Name()if sub.IsDirectory() {- subIsDeletingBucket := f.isBucket(sub)+ subIsDeletingBucket := f.IsBucket(sub)err = f.doBatchDeleteFolderMetaAndData(ctx, sub, isRecursive, ignoreRecursiveError, shouldDeleteChunks, subIsDeletingBucket, false, nil, onHardLinkIdsFn)} else {f.NotifyUpdateEvent(ctx, sub, nil, shouldDeleteChunks, isFromOtherCluster, nil)diff --git a/weed/filer/filer_rename.go b/weed/filer/filer_rename.goindex cf4a2b79f5..b39d9872e1 100644--- a/weed/filer/filer_rename.go+++ b/weed/filer/filer_rename.go@@ -1,18 +1,29 @@package filerimport (+ "context""fmt""strings""github.com/seaweedfs/seaweedfs/weed/util")-func (f *Filer) CanRename(source, target util.FullPath, oldName string) error {+func (f *Filer) CanRename(ctx context.Context, source, target util.FullPath, oldName string) error {sourcePath := source.Child(oldName)if strings.HasPrefix(string(target), string(sourcePath)) {return fmt.Errorf("mv: can not move directory to a subdirectory of itself")}+ // Check if attempting to rename a bucket itself+ // Need to load the entry to check if it's a bucket+ entry, err := f.FindEntry(ctx, sourcePath)+ if err != nil {+ return err+ }+ if f.IsBucket(entry) {+ return fmt.Errorf("bucket renaming is not allowed")+ }+sourceBucket := f.DetectBucket(source)targetBucket := f.DetectBucket(target)if sourceBucket != targetBucket {diff --git a/weed/server/filer_grpc_server_rename.go b/weed/server/filer_grpc_server_rename.goindex db00dd4966..382ed69a8f 100644--- a/weed/server/filer_grpc_server_rename.go+++ b/weed/server/filer_grpc_server_rename.go@@ -19,7 +19,7 @@ func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.AtomoldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))- if err := fs.filer.CanRename(oldParent, newParent, req.OldName); err != nil {+ if err := fs.filer.CanRename(ctx, oldParent, newParent, req.OldName); err != nil {return nil, err}@@ -55,7 +55,7 @@ func (fs *FilerServer) StreamRenameEntry(req *filer_pb.StreamRenameEntryRequest,oldParent := util.FullPath(filepath.ToSlash(req.OldDirectory))newParent := util.FullPath(filepath.ToSlash(req.NewDirectory))- if err := fs.filer.CanRename(oldParent, newParent, req.OldName); err != nil {+ if err := fs.filer.CanRename(stream.Context(), oldParent, newParent, req.OldName); err != nil {return err}