mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
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:
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user