Skip to content

Commit

Permalink
Respect configuration values in other commands to
Browse files Browse the repository at this point in the history
This will implement our configuration setting for all major commands in knoxite.
  • Loading branch information
penguwin committed May 31, 2020
1 parent 3308474 commit 583b7d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/knoxite/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/knoxite/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
32 changes: 30 additions & 2 deletions cmd/knoxite/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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{
Expand Down

0 comments on commit 583b7d4

Please sign in to comment.