mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
40
fs/fs.go
40
fs/fs.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user