vfs: remove un-needed (after introduction of rcat) createInfo struct

This commit is contained in:
Nick Craig-Wood 2017-11-06 12:25:54 +00:00
parent 3fb1e96988
commit a0cfa0929b
4 changed files with 4 additions and 94 deletions

View File

@ -1,60 +0,0 @@
package vfs
import (
"time"
"github.com/ncw/rclone/fs"
)
// info to create a new object
type createInfo struct {
f fs.Fs
remote string
}
func newCreateInfo(f fs.Fs, remote string) *createInfo {
return &createInfo{
f: f,
remote: remote,
}
}
// Fs returns read only access to the Fs that this object is part of
func (ci *createInfo) Fs() fs.Info {
return ci.f
}
// String returns the remote path
func (ci *createInfo) String() string {
return ci.remote
}
// Remote returns the remote path
func (ci *createInfo) Remote() string {
return ci.remote
}
// Hash returns the selected checksum of the file
// If no checksum is available it returns ""
func (ci *createInfo) Hash(fs.HashType) (string, error) {
return "", fs.ErrHashUnsupported
}
// ModTime returns the modification date of the file
// It should return a best guess if one isn't available
func (ci *createInfo) ModTime() time.Time {
return time.Now()
}
// Size returns the size of the file
func (ci *createInfo) Size() int64 {
// FIXME this means this won't work with all remotes...
return 0
}
// Storable says whether this object can be stored
func (ci *createInfo) Storable() bool {
return true
}
var _ fs.ObjectInfo = (*createInfo)(nil)

View File

@ -1,29 +0,0 @@
package vfs
import (
"testing"
"time"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fstest"
"github.com/stretchr/testify/assert"
)
func TestCreateInfo(t *testing.T) {
r := fstest.NewRun(t)
defer r.Finalise()
remote := "file/to/be/created"
ci := newCreateInfo(r.Fremote, remote)
// Test methods
assert.Equal(t, r.Fremote, ci.Fs())
assert.Equal(t, remote, ci.String())
assert.Equal(t, remote, ci.Remote())
_, err := ci.Hash(fs.HashMD5)
assert.Equal(t, fs.ErrHashUnsupported, err)
assert.WithinDuration(t, time.Now(), ci.ModTime(), time.Second)
assert.Equal(t, int64(0), ci.Size())
assert.Equal(t, true, ci.Storable())
}

View File

@ -235,8 +235,7 @@ func (f *File) OpenWrite() (fh *WriteFileHandle, err error) {
}
// fs.Debugf(o, "File.OpenWrite")
src := newCreateInfo(f.d.f, f.path())
fh, err = newWriteFileHandle(f.d, f, src)
fh, err = newWriteFileHandle(f.d, f, f.path())
err = errors.Wrap(err, "open for write")
if err != nil {

View File

@ -30,9 +30,9 @@ var (
_ io.Closer = (*WriteFileHandle)(nil)
)
func newWriteFileHandle(d *Dir, f *File, src fs.ObjectInfo) (*WriteFileHandle, error) {
func newWriteFileHandle(d *Dir, f *File, remote string) (*WriteFileHandle, error) {
fh := &WriteFileHandle{
remote: src.Remote(),
remote: remote,
result: make(chan error, 1),
file: f,
}
@ -40,7 +40,7 @@ func newWriteFileHandle(d *Dir, f *File, src fs.ObjectInfo) (*WriteFileHandle, e
pipeReader, fh.pipeWriter = io.Pipe()
go func() {
// NB Rcat deals with Stats.Transferring etc
o, err := fs.Rcat(d.f, src.Remote(), pipeReader, time.Now())
o, err := fs.Rcat(d.f, remote, pipeReader, time.Now())
if err != nil {
fs.Errorf(fh.remote, "WriteFileHandle.New Rcat failed: %v", err)
}