new rclone package

master
Bel LaPointe 2021-04-18 15:25:09 -05:00
parent be2a031834
commit db72d59589
5 changed files with 36 additions and 30 deletions

View File

@ -1,6 +1,7 @@
package config package config
import ( import (
"context"
"fmt" "fmt"
"local/args" "local/args"
"local/logb" "local/logb"
@ -9,7 +10,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/ncw/rclone/fs/config" "github.com/rclone/rclone/fs/config"
) )
var ( var (
@ -95,8 +96,8 @@ func Refresh() error {
RCloneConfig = as.Get("rcconf").GetString() RCloneConfig = as.Get("rcconf").GetString()
os.Setenv("RCLONE_CONFIG", RCloneConfig) os.Setenv("RCLONE_CONFIG", RCloneConfig)
config.ConfigPath = RCloneConfig config.SetConfigPath(RCloneConfig)
config.LoadConfig() config.LoadConfig(context.Background())
MonitorInterval = as.Get("interval").GetDuration() MonitorInterval = as.Get("interval").GetDuration()
DryRun = as.Get("dry").GetBool() DryRun = as.Get("dry").GetBool()

View File

@ -1,6 +1,7 @@
package rclone package rclone
import ( import (
"context"
"fmt" "fmt"
"io" "io"
"local/logb" "local/logb"
@ -8,21 +9,25 @@ import (
"path" "path"
"time" "time"
_ "github.com/ncw/rclone/backend/drive" _ "github.com/rclone/rclone/backend/drive"
_ "github.com/ncw/rclone/backend/local" _ "github.com/rclone/rclone/backend/local"
_ "github.com/ncw/rclone/backend/s3" _ "github.com/rclone/rclone/backend/s3"
"github.com/ncw/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/ncw/rclone/fs/object" "github.com/rclone/rclone/fs/object"
) )
func (rc *RClone) Context() context.Context {
return context.Background()
}
func (rc *RClone) CopyTo(r io.Reader, destination string) error { func (rc *RClone) CopyTo(r io.Reader, destination string) error {
logb.Verbosef("copy to: %v", destination) logb.Verbosef("copy to: %v", destination)
f, err := fs.NewFs(path.Dir(destination)) f, err := fs.NewFs(rc.Context(), path.Dir(destination))
logb.Verbosef("got new fs: %v", err) logb.Verbosef("got new fs: %v", err)
if err != nil { if err != nil {
return err return err
} }
if info, err := f.NewObject(path.Base(destination)); err == nil { if info, err := f.NewObject(rc.Context(), path.Base(destination)); err == nil {
logb.Warnf("not re-uploading file to: %v: %v", destination, info) logb.Warnf("not re-uploading file to: %v: %v", destination, info)
fmt.Println("copyTo", 3) fmt.Println("copyTo", 3)
return nil return nil
@ -36,21 +41,21 @@ func (rc *RClone) CopyTo(r io.Reader, destination string) error {
logb.Debugf("copy to", info) logb.Debugf("copy to", info)
//return nil TODO //return nil TODO
} }
_, err = f.Put(r, info) _, err = f.Put(rc.Context(), r, info)
return err return err
} }
func (rc *RClone) CopyFrom(w io.Writer, source string) error { func (rc *RClone) CopyFrom(w io.Writer, source string) error {
logb.Infof("copying from %v", source) logb.Infof("copying from %v", source)
f, err := fs.NewFs(path.Dir(source)) f, err := fs.NewFs(rc.Context(), path.Dir(source))
if err != nil { if err != nil {
return err return err
} }
obj, err := f.NewObject(path.Base(source)) obj, err := f.NewObject(rc.Context(), path.Base(source))
if err != nil { if err != nil {
return err return err
} }
r, err := obj.Open() r, err := obj.Open(rc.Context())
if err != nil { if err != nil {
return nil return nil
} }

View File

@ -5,18 +5,18 @@ import (
"local/sandbox/arlo-cleaner/config" "local/sandbox/arlo-cleaner/config"
"path" "path"
_ "github.com/ncw/rclone/backend/drive" _ "github.com/rclone/rclone/backend/drive"
_ "github.com/ncw/rclone/backend/local" _ "github.com/rclone/rclone/backend/local"
_ "github.com/ncw/rclone/backend/s3" _ "github.com/rclone/rclone/backend/s3"
"github.com/ncw/rclone/fs" "github.com/rclone/rclone/fs"
) )
func (rc *RClone) Del(destination string) error { func (rc *RClone) Del(destination string) error {
f, err := fs.NewFs(path.Dir(destination)) f, err := fs.NewFs(rc.Context(), path.Dir(destination))
if err != nil { if err != nil {
return err return err
} }
obj, err := f.NewObject(path.Base(destination)) obj, err := f.NewObject(rc.Context(), path.Base(destination))
if err == fs.ErrorObjectNotFound { if err == fs.ErrorObjectNotFound {
return nil return nil
} else if err != nil { } else if err != nil {
@ -27,5 +27,5 @@ func (rc *RClone) Del(destination string) error {
//return nil TODO //return nil TODO
} }
logb.Infof("removing %v", destination) logb.Infof("removing %v", destination)
return obj.Remove() return obj.Remove(rc.Context())
} }

View File

@ -1,18 +1,18 @@
package rclone package rclone
import ( import (
_ "github.com/ncw/rclone/backend/drive" _ "github.com/rclone/rclone/backend/drive"
_ "github.com/ncw/rclone/backend/local" _ "github.com/rclone/rclone/backend/local"
_ "github.com/ncw/rclone/backend/s3" _ "github.com/rclone/rclone/backend/s3"
"github.com/ncw/rclone/fs" "github.com/rclone/rclone/fs"
) )
func (rc *RClone) List(destination string) ([]string, error) { func (rc *RClone) List(destination string) ([]string, error) {
f, err := fs.NewFs(destination) f, err := fs.NewFs(rc.Context(), destination)
if err != nil { if err != nil {
return nil, err return nil, err
} }
entries, err := f.List("") entries, err := f.List(rc.Context(), "")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,9 +1,9 @@
package rclone package rclone
import ( import (
_ "github.com/ncw/rclone/backend/drive" _ "github.com/rclone/rclone/backend/drive"
_ "github.com/ncw/rclone/backend/local" _ "github.com/rclone/rclone/backend/local"
_ "github.com/ncw/rclone/backend/s3" _ "github.com/rclone/rclone/backend/s3"
) )
type RClone struct{} type RClone struct{}