From 72901e4685c2de1c47c4d96dfcb80afec6a156a7 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 16 Aug 2021 01:40:01 +0200 Subject: [PATCH] copy mutation in dir fix --- internal/helper.go | 4 ++++ internal/mutations.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/internal/helper.go b/internal/helper.go index e27200f..9f7c180 100644 --- a/internal/helper.go +++ b/internal/helper.go @@ -30,3 +30,7 @@ func getPathFromId(id string) string { return dir + "/" } + +func getFilenameFromID(id string) string { + return filepath.Base(id) +} diff --git a/internal/mutations.go b/internal/mutations.go index aaeb81f..a92108f 100644 --- a/internal/mutations.go +++ b/internal/mutations.go @@ -3,6 +3,7 @@ package s3browser import ( "context" "fmt" + "strings" "github.com/minio/minio-go/v7" ) @@ -33,6 +34,13 @@ func copyMutation(ctx context.Context, src, dest string) (*File, error) { return nil, fmt.Errorf("Failed to get s3Client from context") } + // Check if dest is a file or a dir + if strings.HasSuffix(dest, "/") { + // create new dest id + // TODO: What if a file with this id already exists? + dest += getFilenameFromID(src) + } + info, err := s3Client.CopyObject(ctx, minio.CopyDestOptions{ Bucket: bucketName, Object: dest,