2023-11-13 16:40:34 +00:00
|
|
|
// Package s3 implements an s3 server for rclone
|
2022-09-21 15:09:50 +00:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/Mikubill/gofakes3"
|
|
|
|
"github.com/ncw/swift/v2"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/vfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-11-13 16:40:34 +00:00
|
|
|
emptyPrefix = &gofakes3.Prefix{}
|
|
|
|
timeFormat = "Mon, 2 Jan 2006 15:04:05.999999999 GMT"
|
2022-09-21 15:09:50 +00:00
|
|
|
)
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
// s3Backend implements the gofacess3.Backend interface to make an S3
|
|
|
|
// backend for gofakes3
|
2022-09-21 15:09:50 +00:00
|
|
|
type s3Backend struct {
|
|
|
|
opt *Options
|
2023-11-13 16:40:34 +00:00
|
|
|
vfs *vfs.VFS
|
|
|
|
meta *sync.Map
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// newBackend creates a new SimpleBucketBackend.
|
2023-11-13 16:40:34 +00:00
|
|
|
func newBackend(vfs *vfs.VFS, opt *Options) gofakes3.Backend {
|
2022-09-21 15:09:50 +00:00
|
|
|
return &s3Backend{
|
2023-11-13 16:40:34 +00:00
|
|
|
vfs: vfs,
|
|
|
|
opt: opt,
|
|
|
|
meta: new(sync.Map),
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets always returns the default bucket.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) ListBuckets() ([]gofakes3.BucketInfo, error) {
|
|
|
|
dirEntries, err := getDirEntries("/", b.vfs)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var response []gofakes3.BucketInfo
|
|
|
|
for _, entry := range dirEntries {
|
|
|
|
if entry.IsDir() {
|
|
|
|
response = append(response, gofakes3.BucketInfo{
|
|
|
|
Name: gofakes3.URLEncode(entry.Name()),
|
|
|
|
CreationDate: gofakes3.NewContentTime(entry.ModTime()),
|
|
|
|
})
|
|
|
|
}
|
2023-11-13 16:40:34 +00:00
|
|
|
// FIXME: handle files in root dir
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListBucket lists the objects in the given bucket.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) ListBucket(bucket string, prefix *gofakes3.Prefix, page gofakes3.ListBucketPage) (*gofakes3.ObjectList, error) {
|
|
|
|
_, err := b.vfs.Stat(bucket)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.BucketNotFound(bucket)
|
|
|
|
}
|
|
|
|
if prefix == nil {
|
|
|
|
prefix = emptyPrefix
|
|
|
|
}
|
|
|
|
|
|
|
|
// workaround
|
|
|
|
if strings.TrimSpace(prefix.Prefix) == "" {
|
|
|
|
prefix.HasPrefix = false
|
|
|
|
}
|
|
|
|
if strings.TrimSpace(prefix.Delimiter) == "" {
|
|
|
|
prefix.HasDelimiter = false
|
|
|
|
}
|
|
|
|
|
|
|
|
response := gofakes3.NewObjectList()
|
2023-11-13 16:40:34 +00:00
|
|
|
if b.vfs.Fs().Features().BucketBased || prefix.HasDelimiter && prefix.Delimiter != "/" {
|
|
|
|
err = b.getObjectsListArbitrary(bucket, prefix, response)
|
2022-09-21 15:09:50 +00:00
|
|
|
} else {
|
|
|
|
path, remaining := prefixParser(prefix)
|
2023-11-13 16:40:34 +00:00
|
|
|
err = b.entryListR(bucket, path, remaining, prefix.HasDelimiter, response)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
return b.pager(response, page)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HeadObject returns the fileinfo for the given object name.
|
|
|
|
//
|
|
|
|
// Note that the metadata is not supported yet.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) HeadObject(bucketName, objectName string) (*gofakes3.Object, error) {
|
|
|
|
_, err := b.vfs.Stat(bucketName)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.BucketNotFound(bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fp := path.Join(bucketName, objectName)
|
2023-11-13 16:40:34 +00:00
|
|
|
node, err := b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !node.IsFile() {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := node.DirEntry()
|
|
|
|
if entry == nil {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fobj := entry.(fs.Object)
|
|
|
|
size := node.Size()
|
|
|
|
hash := getFileHashByte(fobj)
|
|
|
|
|
|
|
|
meta := map[string]string{
|
|
|
|
"Last-Modified": node.ModTime().Format(timeFormat),
|
|
|
|
"Content-Type": fs.MimeType(context.Background(), fobj),
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
if val, ok := b.meta.Load(fp); ok {
|
2022-09-21 15:09:50 +00:00
|
|
|
metaMap := val.(map[string]string)
|
|
|
|
for k, v := range metaMap {
|
|
|
|
meta[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &gofakes3.Object{
|
|
|
|
Name: objectName,
|
|
|
|
Hash: hash,
|
|
|
|
Metadata: meta,
|
|
|
|
Size: size,
|
|
|
|
Contents: noOpReadCloser{},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObject fetchs the object from the filesystem.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) GetObject(bucketName, objectName string, rangeRequest *gofakes3.ObjectRangeRequest) (obj *gofakes3.Object, err error) {
|
|
|
|
_, err = b.vfs.Stat(bucketName)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.BucketNotFound(bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fp := path.Join(bucketName, objectName)
|
2023-11-13 16:40:34 +00:00
|
|
|
node, err := b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !node.IsFile() {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
entry := node.DirEntry()
|
|
|
|
if entry == nil {
|
|
|
|
return nil, gofakes3.KeyNotFound(objectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fobj := entry.(fs.Object)
|
|
|
|
file := node.(*vfs.File)
|
|
|
|
|
|
|
|
size := node.Size()
|
|
|
|
hash := getFileHashByte(fobj)
|
|
|
|
|
|
|
|
in, err := file.Open(os.O_RDONLY)
|
|
|
|
if err != nil {
|
|
|
|
return nil, gofakes3.ErrInternal
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
// If an error occurs, the caller may not have access to Object.Body in order to close it:
|
|
|
|
if err != nil {
|
|
|
|
_ = in.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
var rdr io.ReadCloser = in
|
|
|
|
rnge, err := rangeRequest.Range(size)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if rnge != nil {
|
|
|
|
if _, err := in.Seek(rnge.Start, io.SeekStart); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
rdr = limitReadCloser(rdr, in.Close, rnge.Length)
|
|
|
|
}
|
|
|
|
|
|
|
|
meta := map[string]string{
|
|
|
|
"Last-Modified": node.ModTime().Format(timeFormat),
|
|
|
|
"Content-Type": fs.MimeType(context.Background(), fobj),
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
if val, ok := b.meta.Load(fp); ok {
|
2022-09-21 15:09:50 +00:00
|
|
|
metaMap := val.(map[string]string)
|
|
|
|
for k, v := range metaMap {
|
|
|
|
meta[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &gofakes3.Object{
|
|
|
|
Name: gofakes3.URLEncode(objectName),
|
|
|
|
Hash: hash,
|
|
|
|
Metadata: meta,
|
|
|
|
Size: size,
|
|
|
|
Range: rnge,
|
|
|
|
Contents: rdr,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TouchObject creates or updates meta on specified object.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) TouchObject(fp string, meta map[string]string) (result gofakes3.PutObjectResult, err error) {
|
|
|
|
_, err = b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err == vfs.ENOENT {
|
2023-11-13 16:40:34 +00:00
|
|
|
f, err := b.vfs.Create(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
_ = f.Close()
|
2023-11-13 16:40:34 +00:00
|
|
|
return b.TouchObject(fp, meta)
|
2022-09-21 15:09:50 +00:00
|
|
|
} else if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
_, err = b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
b.meta.Store(fp, meta)
|
2022-09-21 15:09:50 +00:00
|
|
|
|
|
|
|
if val, ok := meta["X-Amz-Meta-Mtime"]; ok {
|
|
|
|
ti, err := swift.FloatStringToTime(val)
|
|
|
|
if err == nil {
|
2023-11-13 16:40:34 +00:00
|
|
|
return result, b.vfs.Chtimes(fp, ti, ti)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
// ignore error since the file is successfully created
|
|
|
|
}
|
|
|
|
|
|
|
|
if val, ok := meta["mtime"]; ok {
|
|
|
|
ti, err := swift.FloatStringToTime(val)
|
|
|
|
if err == nil {
|
2023-11-13 16:40:34 +00:00
|
|
|
return result, b.vfs.Chtimes(fp, ti, ti)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
// ignore error since the file is successfully created
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject creates or overwrites the object with the given name.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) PutObject(
|
2022-09-21 15:09:50 +00:00
|
|
|
bucketName, objectName string,
|
|
|
|
meta map[string]string,
|
|
|
|
input io.Reader, size int64,
|
|
|
|
) (result gofakes3.PutObjectResult, err error) {
|
2023-11-13 16:40:34 +00:00
|
|
|
_, err = b.vfs.Stat(bucketName)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return result, gofakes3.BucketNotFound(bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fp := path.Join(bucketName, objectName)
|
|
|
|
objectDir := path.Dir(fp)
|
|
|
|
// _, err = db.fs.Stat(objectDir)
|
|
|
|
// if err == vfs.ENOENT {
|
|
|
|
// fs.Errorf(objectDir, "PutObject failed: path not found")
|
|
|
|
// return result, gofakes3.KeyNotFound(objectName)
|
|
|
|
// }
|
|
|
|
|
|
|
|
if objectDir != "." {
|
2023-11-13 16:40:34 +00:00
|
|
|
if err := mkdirRecursive(objectDir, b.vfs); err != nil {
|
2022-09-21 15:09:50 +00:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if size == 0 {
|
|
|
|
// maybe a touch operation
|
2023-11-13 16:40:34 +00:00
|
|
|
return b.TouchObject(fp, meta)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
f, err := b.vfs.Create(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
if _, err := io.Copy(f, input); err != nil {
|
2022-09-21 15:09:50 +00:00
|
|
|
// remove file when i/o error occurred (FsPutErr)
|
|
|
|
_ = f.Close()
|
2023-11-13 16:40:34 +00:00
|
|
|
_ = b.vfs.Remove(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
// remove file when close error occurred (FsPutErr)
|
2023-11-13 16:40:34 +00:00
|
|
|
_ = b.vfs.Remove(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
_, err = b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
b.meta.Store(fp, meta)
|
2022-09-21 15:09:50 +00:00
|
|
|
|
|
|
|
if val, ok := meta["X-Amz-Meta-Mtime"]; ok {
|
|
|
|
ti, err := swift.FloatStringToTime(val)
|
|
|
|
if err == nil {
|
2023-11-13 16:40:34 +00:00
|
|
|
return result, b.vfs.Chtimes(fp, ti, ti)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
// ignore error since the file is successfully created
|
|
|
|
}
|
|
|
|
|
|
|
|
if val, ok := meta["mtime"]; ok {
|
|
|
|
ti, err := swift.FloatStringToTime(val)
|
|
|
|
if err == nil {
|
2023-11-13 16:40:34 +00:00
|
|
|
return result, b.vfs.Chtimes(fp, ti, ti)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
// ignore error since the file is successfully created
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMulti deletes multiple objects in a single request.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) DeleteMulti(bucketName string, objects ...string) (result gofakes3.MultiDeleteResult, rerr error) {
|
2022-09-21 15:09:50 +00:00
|
|
|
for _, object := range objects {
|
2023-11-13 16:40:34 +00:00
|
|
|
if err := b.deleteObject(bucketName, object); err != nil {
|
|
|
|
fs.Errorf("serve s3", "delete object failed: %v", err)
|
2022-09-21 15:09:50 +00:00
|
|
|
result.Error = append(result.Error, gofakes3.ErrorResult{
|
|
|
|
Code: gofakes3.ErrInternal,
|
|
|
|
Message: gofakes3.ErrInternal.Message(),
|
|
|
|
Key: object,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
result.Deleted = append(result.Deleted, gofakes3.ObjectID{
|
|
|
|
Key: object,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObject deletes the object with the given name.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) DeleteObject(bucketName, objectName string) (result gofakes3.ObjectDeleteResult, rerr error) {
|
|
|
|
return result, b.deleteObject(bucketName, objectName)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
// deleteObject deletes the object from the filesystem.
|
|
|
|
func (b *s3Backend) deleteObject(bucketName, objectName string) error {
|
|
|
|
_, err := b.vfs.Stat(bucketName)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return gofakes3.BucketNotFound(bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
fp := path.Join(bucketName, objectName)
|
|
|
|
// S3 does not report an error when attemping to delete a key that does not exist, so
|
|
|
|
// we need to skip IsNotExist errors.
|
2023-11-13 16:40:34 +00:00
|
|
|
if err := b.vfs.Remove(fp); err != nil && !os.IsNotExist(err) {
|
2022-09-21 15:09:50 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
// FIXME: unsafe operation
|
|
|
|
if b.vfs.Fs().Features().CanHaveEmptyDirectories {
|
|
|
|
rmdirRecursive(fp, b.vfs)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateBucket creates a new bucket.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) CreateBucket(name string) error {
|
|
|
|
_, err := b.vfs.Stat(name)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil && err != vfs.ENOENT {
|
|
|
|
return gofakes3.ErrInternal
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return gofakes3.ErrBucketAlreadyExists
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
if err := b.vfs.Mkdir(name, 0755); err != nil {
|
2022-09-21 15:09:50 +00:00
|
|
|
return gofakes3.ErrInternal
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteBucket deletes the bucket with the given name.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) DeleteBucket(name string) error {
|
|
|
|
_, err := b.vfs.Stat(name)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return gofakes3.BucketNotFound(name)
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
if err := b.vfs.Remove(name); err != nil {
|
2022-09-21 15:09:50 +00:00
|
|
|
return gofakes3.ErrBucketNotEmpty
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// BucketExists checks if the bucket exists.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) BucketExists(name string) (exists bool, err error) {
|
|
|
|
_, err = b.vfs.Stat(name)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject copy specified object from srcKey to dstKey.
|
2023-11-13 16:40:34 +00:00
|
|
|
func (b *s3Backend) CopyObject(srcBucket, srcKey, dstBucket, dstKey string, meta map[string]string) (result gofakes3.CopyObjectResult, err error) {
|
2022-09-21 15:09:50 +00:00
|
|
|
fp := path.Join(srcBucket, srcKey)
|
|
|
|
if srcBucket == dstBucket && srcKey == dstKey {
|
2023-11-13 16:40:34 +00:00
|
|
|
b.meta.Store(fp, meta)
|
2022-09-21 15:09:50 +00:00
|
|
|
|
|
|
|
val, ok := meta["X-Amz-Meta-Mtime"]
|
|
|
|
if !ok {
|
|
|
|
if val, ok = meta["mtime"]; !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// update modtime
|
|
|
|
ti, err := swift.FloatStringToTime(val)
|
|
|
|
if err != nil {
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
return result, b.vfs.Chtimes(fp, ti, ti)
|
2022-09-21 15:09:50 +00:00
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
cStat, err := b.vfs.Stat(fp)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
c, err := b.GetObject(srcBucket, srcKey, nil)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
_ = c.Contents.Close()
|
|
|
|
}()
|
|
|
|
|
|
|
|
for k, v := range c.Metadata {
|
|
|
|
if _, found := meta[k]; !found && k != "X-Amz-Acl" {
|
|
|
|
meta[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := meta["mtime"]; !ok {
|
|
|
|
meta["mtime"] = swift.TimeToFloatString(cStat.ModTime())
|
|
|
|
}
|
|
|
|
|
2023-11-13 16:40:34 +00:00
|
|
|
_, err = b.PutObject(dstBucket, dstKey, meta, c.Contents, c.Size)
|
2022-09-21 15:09:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return gofakes3.CopyObjectResult{
|
|
|
|
ETag: `"` + hex.EncodeToString(c.Hash) + `"`,
|
|
|
|
LastModified: gofakes3.NewContentTime(cStat.ModTime()),
|
|
|
|
}, nil
|
|
|
|
}
|