fix: S3 Implementation bug & Support AWS Signature V2 (#6683)
* Fix: when S3 PutObject with objectName contains /, aliyundriveopen failed due to KeyNotFound, make dir to fix this. (cherry picked from commit eb24f45771d29a3659e75813734b290d6306cfcf) * Upgrade gofakes3 to v0.0.5, support AWS Signature V2 (cherry picked from commit 3218d7cf2c4e1a8c51fd2414595547fd109a89ac) --------- Co-authored-by: David Hao <akang943578@gmail.com>
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
@ -21,6 +22,7 @@ import (
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/gofakes3"
|
||||
"github.com/ncw/swift/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -268,9 +270,19 @@ func (b *s3Backend) PutObject(
|
||||
fp := path.Join(bucketPath, objectName)
|
||||
reqPath := path.Dir(fp)
|
||||
fmeta, _ := op.GetNearestMeta(fp)
|
||||
_, err = fs.Get(context.WithValue(ctx, "meta", fmeta), reqPath, &fs.GetArgs{})
|
||||
ctx = context.WithValue(ctx, "meta", fmeta)
|
||||
|
||||
_, err = fs.Get(ctx, reqPath, &fs.GetArgs{})
|
||||
if err != nil {
|
||||
return result, gofakes3.KeyNotFound(objectName)
|
||||
if errs.IsObjectNotFound(err) && strings.Contains(objectName, "/") {
|
||||
log.Debugf("reqPath: %s not found and objectName contains /, need to makeDir", reqPath)
|
||||
err = fs.MakeDir(ctx, reqPath, true)
|
||||
if err != nil {
|
||||
return result, errors.WithMessagef(err, "failed to makeDir, reqPath: %s", reqPath)
|
||||
}
|
||||
} else {
|
||||
return result, gofakes3.KeyNotFound(objectName)
|
||||
}
|
||||
}
|
||||
|
||||
var ti time.Time
|
||||
|
Reference in New Issue
Block a user