Merge pull request #175 from alimy/jc/alimy

fixed path error when use OSS:TempDir
pull/176/head
Michael Li 2 years ago committed by GitHub
commit 2afb8af237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -82,14 +82,15 @@ func (s *aliossCreateRetentionServant) PersistObject(objectKey string) error {
}
func (s *aliossCreateTempDirServant) PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string, persistance bool) (string, error) {
objectName := objectKey
if !persistance {
objectKey = s.tempDir + objectKey
objectName = s.tempDir + objectKey
}
options := []oss.Option{
oss.ContentLength(objectSize),
oss.ContentType(contentType),
}
err := s.bucket.PutObject(objectKey, reader, options...)
err := s.bucket.PutObject(objectName, reader, options...)
if err != nil {
return "", err
}
@ -102,6 +103,7 @@ func (s *aliossCreateTempDirServant) PersistObject(objectKey string) error {
return err
}
if exsit {
logrus.Debugf("object exist so do nothing objectKey: %s", objectKey)
return nil
}
if _, err := s.bucket.CopyObject(s.tempDir+objectKey, objectKey); err != nil {

@ -60,10 +60,11 @@ func (s *cosCreateServant) PersistObject(_objectKey string) error {
}
func (s *cosCreateTempDirServant) PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string, persistance bool) (string, error) {
objectName := objectKey
if !persistance {
objectKey = s.tempDir + objectKey
objectName = s.tempDir + objectKey
}
_, err := s.client.Object.Put(context.Background(), objectKey, reader, &cos.ObjectPutOptions{
_, err := s.client.Object.Put(context.Background(), objectName, reader, &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
ContentType: contentType,
ContentLength: objectSize,
@ -81,6 +82,7 @@ func (s *cosCreateTempDirServant) PersistObject(objectKey string) error {
return err
}
if exsit {
logrus.Debugf("object exist so do nothing objectKey: %s", objectKey)
return nil
}
_, _, err = s.client.Object.Copy(context.Background(), objectKey, s.bucketUrl+s.tempDir+objectKey, nil)

@ -86,11 +86,12 @@ func (s *hwobsCreateRetentionServant) PersistObject(objectKey string) error {
}
func (s *hwobsCreateTempDirServant) PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string, persistance bool) (string, error) {
objectName := objectKey
if !persistance {
objectKey = s.tempDir + objectKey
objectName = s.tempDir + objectKey
}
input := &obs.PutObjectInput{}
input.Bucket, input.Key, input.Body = s.bucket, objectKey, reader
input.Bucket, input.Key, input.Body = s.bucket, objectName, reader
input.ContentType, input.ContentLength = contentType, objectSize
_, err := s.client.PutObject(input)
if err != nil {
@ -107,7 +108,7 @@ func (s *hwobsCreateTempDirServant) PersistObject(objectKey string) error {
}
_, err := s.client.GetObjectMetadata(input)
if err == nil {
// do nothing if object exist
logrus.Debugf("object exist so do nothing objectKey: %s", objectKey)
return nil
}

@ -11,6 +11,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/sirupsen/logrus"
)
var (
@ -70,16 +71,17 @@ func (s *localossCreateServant) PersistObject(_objectKey string) error {
}
func (s *localossCreateTempDirServant) PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string, persistance bool) (string, error) {
objectName := objectKey
if !persistance {
objectKey = s.tempDir + objectKey
objectName = s.tempDir + objectKey
}
saveDir := s.savePath + filepath.Dir(objectKey)
saveDir := s.savePath + filepath.Dir(objectName)
err := os.MkdirAll(saveDir, 0750)
if err != nil && !os.IsExist(err) {
return "", err
}
savePath := s.savePath + objectKey
savePath := s.savePath + objectName
writer, err := os.Create(savePath)
if err != nil {
return "", err
@ -104,7 +106,7 @@ func (s *localossCreateTempDirServant) PersistObject(objectKey string) error {
return err
}
if !fi.IsDir() {
// do nothing if object is exsit
logrus.Debugf("object exist so do nothing objectKey: %s", objectKey)
return nil
}

@ -10,6 +10,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/minio/minio-go/v7"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/sirupsen/logrus"
)
var (
@ -88,10 +89,11 @@ func (s *minioCreateRetentionServant) PersistObject(objectKey string) error {
func (s *minioCreateTempDirServant) PutObject(objectKey string, reader io.Reader, objectSize int64, contentType string, persistance bool) (string, error) {
opts := minio.PutObjectOptions{ContentType: contentType}
objectName := objectKey
if !persistance {
objectKey = s.tempDir + objectKey
objectName = s.tempDir + objectKey
}
_, err := s.client.PutObject(context.Background(), s.bucket, objectKey, reader, objectSize, opts)
_, err := s.client.PutObject(context.Background(), s.bucket, objectName, reader, objectSize, opts)
if err != nil {
return "", err
}
@ -101,7 +103,7 @@ func (s *minioCreateTempDirServant) PutObject(objectKey string, reader io.Reader
func (s *minioCreateTempDirServant) PersistObject(objectKey string) error {
_, err := s.client.StatObject(context.Background(), s.bucket, objectKey, minio.StatObjectOptions{})
if err == nil {
// do nothing if object exist
logrus.Debugf("object exist so do nothing objectKey: %s", objectKey)
return nil
}

Loading…
Cancel
Save