Skip to content

Commit

Permalink
cmd/gateway: create dst dir path when copy-object (#4058)
Browse files Browse the repository at this point in the history
Create the parent directory of the target on demand when need
Co-authored-by: Davies Liu <[email protected]>
  • Loading branch information
zhijian-pro authored and SandyXSD committed Nov 24, 2023
1 parent 08031fc commit 1df515c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions integration/s3gateway_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1df515c

Please sign in to comment.