implement rcat – fixes #230, fixes #1001

This commit is contained in:
Stefan Breunig
2017-08-03 21:42:35 +02:00
parent 3e3a59768e
commit 28a18303f3
32 changed files with 1223 additions and 916 deletions

View File

@@ -3,8 +3,10 @@ package fs
import (
"io"
"io/ioutil"
"log"
"math"
"os"
"path/filepath"
"regexp"
"sort"
@@ -304,6 +306,13 @@ type Features struct {
// exists.
PutUnchecked func(in io.Reader, src ObjectInfo, options ...OpenOption) (Object, error)
// PutStream uploads to the remote path with the modTime given of indeterminate size
//
// May create the object even if it returns an error - if so
// will return the object and the error, otherwise will return
// nil and the error
PutStream func(in io.Reader, src ObjectInfo, options ...OpenOption) (Object, error)
// CleanUp the trash in the Fs
//
// Implement this if you have a way of emptying the trash or
@@ -357,6 +366,9 @@ func (ft *Features) Fill(f Fs) *Features {
if do, ok := f.(PutUncheckeder); ok {
ft.PutUnchecked = do.PutUnchecked
}
if do, ok := f.(PutStreamer); ok {
ft.PutStream = do.PutStream
}
if do, ok := f.(CleanUpper); ok {
ft.CleanUp = do.CleanUp
}
@@ -402,6 +414,9 @@ func (ft *Features) Mask(f Fs) *Features {
if mask.PutUnchecked == nil {
ft.PutUnchecked = nil
}
if mask.PutStream == nil {
ft.PutStream = nil
}
if mask.CleanUp == nil {
ft.CleanUp = nil
}
@@ -508,6 +523,16 @@ type PutUncheckeder interface {
PutUnchecked(in io.Reader, src ObjectInfo, options ...OpenOption) (Object, error)
}
// PutStreamer is an optional interface for Fs
type PutStreamer interface {
// PutStream uploads to the remote path with the modTime given of indeterminate size
//
// May create the object even if it returns an error - if so
// will return the object and the error, otherwise will return
// nil and the error
PutStream(in io.Reader, src ObjectInfo, options ...OpenOption) (Object, error)
}
// CleanUpper is an optional interfaces for Fs
type CleanUpper interface {
// CleanUp the trash in the Fs
@@ -617,6 +642,21 @@ func NewFs(path string) (Fs, error) {
return fsInfo.NewFs(configName, fsPath)
}
// temporaryLocalFs creates a local FS in the OS's temporary directory.
//
// No cleanup is performed, the caller must call Purge on the Fs themselves.
func temporaryLocalFs() (Fs, error) {
path, err := ioutil.TempDir("", "rclone-spool")
if err == nil {
err = os.Remove(path)
}
if err != nil {
return nil, err
}
path = filepath.ToSlash(path)
return NewFs(path)
}
// CheckClose is a utility function used to check the return from
// Close in a defer statement.
func CheckClose(c io.Closer, err *error) {