copy mutation in dir fix

This commit is contained in:
Niklas 2021-08-16 01:40:01 +02:00
parent 33237b6564
commit 72901e4685
2 changed files with 12 additions and 0 deletions

View File

@ -30,3 +30,7 @@ func getPathFromId(id string) string {
return dir + "/"
}
func getFilenameFromID(id string) string {
return filepath.Base(id)
}

View File

@ -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,