From 1df515caab9b70de3ceb4dad7eaebd37e922b5c0 Mon Sep 17 00:00:00 2001 From: zhijian Date: Thu, 21 Sep 2023 20:41:09 +0800 Subject: [PATCH] cmd/gateway: create dst dir path when copy-object (#4058) Create the parent directory of the target on demand when need Co-authored-by: Davies Liu --- integration/s3gateway_test.sh | 13 +++++++++++++ pkg/gateway/gateway.go | 1 + 2 files changed, 14 insertions(+) diff --git a/integration/s3gateway_test.sh b/integration/s3gateway_test.sh index 3ee4c5b5a3c8..ff0ee1310fb1 100755 --- a/integration/s3gateway_test.sh +++ b/integration/s3gateway_test.sh @@ -736,6 +736,19 @@ function test_copy_object() { fi fi + if [ $rv -eq 0 ]; then + function="${AWS} s3api copy-object --bucket ${bucket_name} --key /not-exist-dir/datafile-1-kB-copy --copy-source ${bucket_name}/datafile-1-kB" + test_function=${function} + out=$($function) + rv=$? + hash2=$(echo "$out" | jq -r .CopyObjectResult.ETag | sed -e 's/^"//' -e 's/"$//') + if [ $rv -eq 0 ] && [ "$HASH_1_KB" != "$hash2" ]; then + # Verification failed + rv=1 + out="Hash mismatch expected $HASH_1_KB, got $hash2" + fi + fi + ${AWS} s3 rb s3://"${bucket_name}" --force > /dev/null 2>&1 if [ $rv -eq 0 ]; then log_success "$(get_duration "$start_time")" "${test_function}" diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 5be569d097e3..cad1bf912acf 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -480,6 +480,7 @@ func (n *jfsObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBu logger.Errorf("copy %s to %s: %s", src, tmp, err) return } + _ = n.mkdirAll(ctx, path.Dir(dst), os.FileMode(n.gConf.DirMode)) eno = n.fs.Rename(mctx, tmp, dst, 0) if eno != 0 { err = jfsToObjectErr(ctx, eno, srcBucket, srcObject)