fs: move operations.NewOverrideRemote to fs.NewOverrideRemote

This commit is contained in:
Nick Craig-Wood 2022-08-06 16:30:45 +01:00
parent 7db1c506f2
commit dd71f5d968
5 changed files with 76 additions and 73 deletions

View File

@ -631,7 +631,7 @@ func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, stream bo
if err != nil {
return nil, err
}
uSrc := operations.NewOverrideRemote(src, uRemote)
uSrc := fs.NewOverrideRemote(src, uRemote)
var o fs.Object
if stream {
o, err = u.f.Features().PutStream(ctx, in, uSrc, options...)

View File

@ -12,7 +12,6 @@ import (
_ "github.com/rclone/rclone/backend/local"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/hash"
"github.com/rclone/rclone/fs/operations"
"github.com/rclone/rclone/fstest"
"github.com/rclone/rclone/lib/random"
"github.com/stretchr/testify/assert"
@ -56,7 +55,7 @@ func TestIntegration(t *testing.T) {
require.NoError(t, err)
in, err := srcObj.Open(ctx)
require.NoError(t, err)
dstObj, err := f.Put(ctx, in, operations.NewOverrideRemote(srcObj, remote))
dstObj, err := f.Put(ctx, in, fs.NewOverrideRemote(srcObj, remote))
require.NoError(t, err)
assert.Equal(t, remote, dstObj.Remote())
_ = in.Close()
@ -221,7 +220,7 @@ func TestIntegration(t *testing.T) {
require.NoError(t, err)
in, err := srcObj.Open(ctx)
require.NoError(t, err)
dstObj, err := f.Put(ctx, in, operations.NewOverrideRemote(srcObj, remote))
dstObj, err := f.Put(ctx, in, fs.NewOverrideRemote(srcObj, remote))
require.NoError(t, err)
assert.Equal(t, remote, dstObj.Remote())
_ = in.Close()

View File

@ -297,74 +297,6 @@ func removeFailedCopy(ctx context.Context, dst fs.Object) bool {
return true
}
// OverrideRemote is a wrapper to override the Remote for an
// ObjectInfo
type OverrideRemote struct {
fs.ObjectInfo
remote string
}
// NewOverrideRemote returns an OverrideRemoteObject which will
// return the remote specified
func NewOverrideRemote(oi fs.ObjectInfo, remote string) *OverrideRemote {
return &OverrideRemote{
ObjectInfo: oi,
remote: remote,
}
}
// Remote returns the overridden remote name
func (o *OverrideRemote) Remote() string {
return o.remote
}
// MimeType returns the mime type of the underlying object or "" if it
// can't be worked out
func (o *OverrideRemote) MimeType(ctx context.Context) string {
if do, ok := o.ObjectInfo.(fs.MimeTyper); ok {
return do.MimeType(ctx)
}
return ""
}
// ID returns the ID of the Object if known, or "" if not
func (o *OverrideRemote) ID() string {
if do, ok := o.ObjectInfo.(fs.IDer); ok {
return do.ID()
}
return ""
}
// UnWrap returns the Object that this Object is wrapping or nil if it
// isn't wrapping anything
func (o *OverrideRemote) UnWrap() fs.Object {
if o, ok := o.ObjectInfo.(fs.Object); ok {
return o
}
return nil
}
// GetTier returns storage tier or class of the Object
func (o *OverrideRemote) GetTier() string {
if do, ok := o.ObjectInfo.(fs.GetTierer); ok {
return do.GetTier()
}
return ""
}
// Metadata returns metadata for an object
//
// It should return nil if there is no Metadata
func (o *OverrideRemote) Metadata(ctx context.Context) (fs.Metadata, error) {
if do, ok := o.ObjectInfo.(fs.Metadataer); ok {
return do.Metadata(ctx)
}
return nil, nil
}
// Check all optional interfaces satisfied
var _ fs.FullObjectInfo = (*OverrideRemote)(nil)
// CommonHash returns a single hash.Type and a HashOption with that
// type which is in common between the two fs.Fs.
func CommonHash(ctx context.Context, fa, fb fs.Info) (hash.Type, *fs.HashesOption) {
@ -491,7 +423,7 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj
var wrappedSrc fs.ObjectInfo = src
// We try to pass the original object if possible
if src.Remote() != remote {
wrappedSrc = NewOverrideRemote(src, remote)
wrappedSrc = fs.NewOverrideRemote(src, remote)
}
options := []fs.OpenOption{hashOption}
for _, option := range ci.UploadHeaders {

68
fs/override.go Normal file
View File

@ -0,0 +1,68 @@
package fs
import "context"
// OverrideRemote is a wrapper to override the Remote for an
// ObjectInfo
type OverrideRemote struct {
ObjectInfo
remote string
}
// NewOverrideRemote returns an OverrideRemoteObject which will
// return the remote specified
func NewOverrideRemote(oi ObjectInfo, remote string) *OverrideRemote {
return &OverrideRemote{
ObjectInfo: oi,
remote: remote,
}
}
// Remote returns the overridden remote name
func (o *OverrideRemote) Remote() string {
return o.remote
}
// MimeType returns the mime type of the underlying object or "" if it
// can't be worked out
func (o *OverrideRemote) MimeType(ctx context.Context) string {
if do, ok := o.ObjectInfo.(MimeTyper); ok {
return do.MimeType(ctx)
}
return ""
}
// ID returns the ID of the Object if known, or "" if not
func (o *OverrideRemote) ID() string {
if do, ok := o.ObjectInfo.(IDer); ok {
return do.ID()
}
return ""
}
// UnWrap returns the Object that this Object is wrapping or nil if it
// isn't wrapping anything
func (o *OverrideRemote) UnWrap() Object {
if o, ok := o.ObjectInfo.(Object); ok {
return o
}
return nil
}
// GetTier returns storage tier or class of the Object
func (o *OverrideRemote) GetTier() string {
if do, ok := o.ObjectInfo.(GetTierer); ok {
return do.GetTier()
}
return ""
}
// Metadata returns metadata for an object
//
// It should return nil if there is no Metadata
func (o *OverrideRemote) Metadata(ctx context.Context) (Metadata, error) {
if do, ok := o.ObjectInfo.(Metadataer); ok {
return do.Metadata(ctx)
}
return nil, nil
}

4
fs/override_test.go Normal file
View File

@ -0,0 +1,4 @@
package fs
// Check all optional interfaces satisfied
var _ FullObjectInfo = (*OverrideRemote)(nil)