Files
arlo-cleaner/rclone/copy.go
Bel LaPointe be2a031834 initial
2021-03-28 13:12:15 -05:00

60 lines
1.4 KiB
Go
Executable File

package rclone
import (
"fmt"
"io"
"local/logb"
"local/sandbox/arlo-cleaner/config"
"path"
"time"
_ "github.com/ncw/rclone/backend/drive"
_ "github.com/ncw/rclone/backend/local"
_ "github.com/ncw/rclone/backend/s3"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/object"
)
func (rc *RClone) CopyTo(r io.Reader, destination string) error {
logb.Verbosef("copy to: %v", destination)
f, err := fs.NewFs(path.Dir(destination))
logb.Verbosef("got new fs: %v", err)
if err != nil {
return err
}
if info, err := f.NewObject(path.Base(destination)); err == nil {
logb.Warnf("not re-uploading file to: %v: %v", destination, info)
fmt.Println("copyTo", 3)
return nil
} else {
logb.Verbosef("error listing existing object as expected: %v, %v", err, info)
}
logb.Verbosef("new obj err: %v", nil)
info := object.NewStaticObjectInfo(path.Base(destination), time.Now(), 0, true, nil, f)
logb.Infof("uploading %v", destination)
if config.DryRun {
logb.Debugf("copy to", info)
//return nil TODO
}
_, err = f.Put(r, info)
return err
}
func (rc *RClone) CopyFrom(w io.Writer, source string) error {
logb.Infof("copying from %v", source)
f, err := fs.NewFs(path.Dir(source))
if err != nil {
return err
}
obj, err := f.NewObject(path.Base(source))
if err != nil {
return err
}
r, err := obj.Open()
if err != nil {
return nil
}
_, err = io.Copy(w, r)
return err
}