diff --git a/cmd/knoxite/clone.go b/cmd/knoxite/clone.go index 196ce64c..e3cc2795 100644 --- a/cmd/knoxite/clone.go +++ b/cmd/knoxite/clone.go @@ -31,6 +31,8 @@ var ( if len(args) < 2 { return fmt.Errorf("clone needs to know which files and/or directories to work on") } + cloneOpts = configureStoreOpts(cmd, cloneOpts) + return executeClone(args[0], args[1:], cloneOpts) }, } diff --git a/cmd/knoxite/repository.go b/cmd/knoxite/repository.go index d979f83f..40e7b96f 100644 --- a/cmd/knoxite/repository.go +++ b/cmd/knoxite/repository.go @@ -253,6 +253,9 @@ func openRepository(path, password string) (knoxite.Repository, error) { } } + if rep, ok := config.Repositories[path]; ok { + return knoxite.OpenRepository(rep.Url, password) + } return knoxite.OpenRepository(path, password) } diff --git a/cmd/knoxite/store.go b/cmd/knoxite/store.go index 0a0620c5..fd654e9d 100644 --- a/cmd/knoxite/store.go +++ b/cmd/knoxite/store.go @@ -52,11 +52,32 @@ var ( if len(args) < 2 { return fmt.Errorf("store needs to know which files and/or directories to work on") } + storeOpts = configureStoreOpts(cmd, storeOpts) + return executeStore(args[0], args[1:], storeOpts) }, } ) +// configureStoreOpts will compare the the setting from the configration file and +// the user set command line flags. +// When there exists a config for the repo we'll use the values from +// there unless the user sets another value via the command line flags. +func configureStoreOpts(cmd *cobra.Command, opts StoreOptions) StoreOptions { + if rep, ok := config.Repositories[globalOpts.Repo]; ok { + if !cmd.Flags().Changed("compression") { + opts.Compression = rep.Compression + } + if !cmd.Flags().Changed("encryption") { + opts.Encryption = rep.Encryption + } + if !cmd.Flags().Changed("tolerance") { + opts.FailureTolerance = rep.Tolerance + } + } + return opts +} + func initStoreFlags(f func() *pflag.FlagSet) { f().StringVarP(&storeOpts.Description, "desc", "d", "", "a description or comment for this volume") f().StringVarP(&storeOpts.Compression, "compression", "c", "", "compression algo to use: none (default), flate, gzip, lzma, zlib, zstd") @@ -79,7 +100,7 @@ func store(repository *knoxite.Repository, chunkIndex *knoxite.ChunkIndex, snaps return gerr } - if uint(len(repository.BackendManager().Backends))-opts.FailureTolerance <= 0 { + if len(repository.BackendManager().Backends)-int(opts.FailureTolerance) <= 0 { return ErrRedundancyAmount } compression, err := utils.CompressionTypeFromString(opts.Compression) @@ -91,10 +112,17 @@ func store(repository *knoxite.Repository, chunkIndex *knoxite.ChunkIndex, snaps return err } + var tol uint + if inttol := len(repository.BackendManager().Backends) - int(opts.FailureTolerance); inttol <= 0 { + tol = 0 + } else { + tol = uint(inttol) + } + startTime := time.Now() progress := snapshot.Add(wd, targets, opts.Excludes, *repository, chunkIndex, compression, encryption, - uint(len(repository.BackendManager().Backends))-opts.FailureTolerance, opts.FailureTolerance) + tol, opts.FailureTolerance) fileProgressBar := &goprogressbar.ProgressBar{Width: 40} overallProgressBar := &goprogressbar.ProgressBar{