diff --git a/internal/dao/storage/alioss.go b/internal/dao/storage/alioss.go index 8baf3ed3..3519cba5 100644 --- a/internal/dao/storage/alioss.go +++ b/internal/dao/storage/alioss.go @@ -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 { diff --git a/internal/dao/storage/cos.go b/internal/dao/storage/cos.go index 8023e3a6..f7a7ebad 100644 --- a/internal/dao/storage/cos.go +++ b/internal/dao/storage/cos.go @@ -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) diff --git a/internal/dao/storage/huaweiobs.go b/internal/dao/storage/huaweiobs.go index e8302f2d..31656e6c 100644 --- a/internal/dao/storage/huaweiobs.go +++ b/internal/dao/storage/huaweiobs.go @@ -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 } diff --git a/internal/dao/storage/localoss.go b/internal/dao/storage/localoss.go index 3278d85e..503d64c5 100644 --- a/internal/dao/storage/localoss.go +++ b/internal/dao/storage/localoss.go @@ -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 } diff --git a/internal/dao/storage/minio.go b/internal/dao/storage/minio.go index dae6d0ad..b4da9fed 100644 --- a/internal/dao/storage/minio.go +++ b/internal/dao/storage/minio.go @@ -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 }