fix(s3): return NoSuchKey for missing copy sources

- Translate missing source errors during both CopyObject reads
- Add regression coverage for copying a nonexistent source key

Co-authored-by: Codex <267193182+codex@users.noreply.github.com>
Signed-off-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com>
This commit is contained in:
jyxjjj
2026-09-20 01:01:01 +08:00
parent 23164ac7f2
commit 7b4d4454a8
2 changed files with 23 additions and 0 deletions
+6
View File
@@ -451,11 +451,17 @@ func (b *s3Backend) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket
fmeta, _ := op.GetNearestMeta(srcFp)
srcNode, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), srcFp, &fs.GetArgs{})
if err != nil {
if errs.IsObjectNotFound(err) {
return result, gofakes3.KeyNotFound(srcKey)
}
return result, err
}
c, err := b.GetObject(ctx, srcBucket, srcKey, nil)
if err != nil {
if errs.IsObjectNotFound(err) {
return result, gofakes3.KeyNotFound(srcKey)
}
return
}
defer func() {
+17
View File
@@ -0,0 +1,17 @@
package s3
import (
"context"
"testing"
"github.com/OpenListTeam/gofakes3"
)
func TestCopyObjectMissingSourceReturnsNoSuchKey(t *testing.T) {
b, _ := setupMultipartBackend(t)
_, err := b.CopyObject(context.Background(), "mp", "missing.txt", "mp", "copy.txt", nil)
if code := s3ErrorCode(err); code != gofakes3.ErrNoSuchKey {
t.Fatalf("CopyObject() error = %v, want NoSuchKey", code)
}
}