fis: Fixes the trailing slash issue in CopyObject destination and source object paths in posix.

Fixes #1021

`foo` and `foo/` object paths were considered as the same in `CopyObject` source and destination object paths in posix.
Implements the `joinPathWithTrailer` function, which calls `filepath.Join` and adds trailing `/` if it existed in the original path. This way the implementation puts separation
 between directory and file objects with the same name.
This commit is contained in:
niksis02
2025-04-01 17:31:02 +04:00
parent 5e0ea54f99
commit 03c7c432ad
3 changed files with 62 additions and 4 deletions

View File

@@ -3844,8 +3844,8 @@ func (p *Posix) CopyObject(ctx context.Context, input s3response.CopyObjectInput
}
if string(vId) != srcVersionId {
srcBucket = filepath.Join(p.versioningDir, srcBucket)
srcObject = filepath.Join(genObjVersionKey(srcObject), srcVersionId)
srcBucket = joinPathWithTrailer(p.versioningDir, srcBucket)
srcObject = joinPathWithTrailer(genObjVersionKey(srcObject), srcVersionId)
}
}
@@ -3857,7 +3857,7 @@ func (p *Posix) CopyObject(ctx context.Context, input s3response.CopyObjectInput
return nil, fmt.Errorf("stat bucket: %w", err)
}
objPath := filepath.Join(srcBucket, srcObject)
objPath := joinPathWithTrailer(srcBucket, srcObject)
f, err := os.Open(objPath)
if errors.Is(err, fs.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) {
if p.versioningEnabled() && vEnabled {
@@ -3896,7 +3896,7 @@ func (p *Posix) CopyObject(ctx context.Context, input s3response.CopyObjectInput
var crc64nvme *string
var chType types.ChecksumType
dstObjdPath := filepath.Join(dstBucket, dstObject)
dstObjdPath := joinPathWithTrailer(dstBucket, dstObject)
if dstObjdPath == objPath {
if input.MetadataDirective == types.MetadataDirectiveCopy {
return &s3.CopyObjectOutput{}, s3err.GetAPIError(s3err.ErrInvalidCopyDest)
@@ -4917,3 +4917,11 @@ func getString(str *string) string {
}
return *str
}
func joinPathWithTrailer(paths ...string) string {
joined := filepath.Join(paths...)
if strings.HasSuffix(paths[len(paths)-1], "/") {
joined += "/"
}
return joined
}