mirror of
https://github.com/kopia/kopia.git
synced 2026-02-18 15:05:46 -05:00
* refactor: move from io/ioutil to io and os package The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> * chore: remove //nolint:gosec for os.ReadFile At the time of this commit, the G304 rule of gosec does not include the `os.ReadFile` function. We remove `//nolint:gosec` temporarily until https://github.com/securego/gosec/pull/706 is merged. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
50 lines
1.8 KiB
Go
50 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/alecthomas/kingpin"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo/blob"
|
|
"github.com/kopia/kopia/repo/blob/rclone"
|
|
)
|
|
|
|
type storageRcloneFlags struct {
|
|
opt rclone.Options
|
|
connectFlat bool
|
|
embedRCloneConfigFile string
|
|
}
|
|
|
|
func (c *storageRcloneFlags) setup(_ storageProviderServices, cmd *kingpin.CmdClause) {
|
|
cmd.Flag("remote-path", "Rclone remote:path").Required().StringVar(&c.opt.RemotePath)
|
|
cmd.Flag("flat", "Use flat directory structure").BoolVar(&c.connectFlat)
|
|
cmd.Flag("rclone-exe", "Path to rclone binary").StringVar(&c.opt.RCloneExe)
|
|
cmd.Flag("rclone-args", "Pass additional parameters to rclone").StringsVar(&c.opt.RCloneArgs)
|
|
cmd.Flag("rclone-env", "Pass additional environment (key=value) to rclone").StringsVar(&c.opt.RCloneEnv)
|
|
cmd.Flag("embed-rclone-config", "Embed the provider RClone config").ExistingFileVar(&c.embedRCloneConfigFile)
|
|
cmd.Flag("rclone-debug", "Log rclone output").Hidden().BoolVar(&c.opt.Debug)
|
|
cmd.Flag("rclone-nowait-for-transfers", "Don't wait for transfers when closing storage").Hidden().BoolVar(&c.opt.NoWaitForTransfers)
|
|
cmd.Flag("list-parallelism", "Set list parallelism").Hidden().IntVar(&c.opt.ListParallelism)
|
|
cmd.Flag("atomic-writes", "Assume provider writes are atomic").Default("true").BoolVar(&c.opt.AtomicWrites)
|
|
}
|
|
|
|
func (c *storageRcloneFlags) connect(ctx context.Context, isNew bool) (blob.Storage, error) {
|
|
if c.connectFlat {
|
|
c.opt.DirectoryShards = []int{}
|
|
}
|
|
|
|
if c.embedRCloneConfigFile != "" {
|
|
cfg, err := os.ReadFile(c.embedRCloneConfigFile)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "unable to read rclone config file")
|
|
}
|
|
|
|
c.opt.EmbeddedConfig = string(cfg)
|
|
}
|
|
|
|
// nolint:wrapcheck
|
|
return rclone.New(ctx, &c.opt)
|
|
}
|