Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format bool arguments in a way it expected by kopia's cmd lib. #1849

Merged
merged 5 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
ownerFlag = "--owner"
sparseFlag = "--write-sparse-files"
ignorePermissionsError = "--ignore-permission-errors"
noIgnorePermissionsError = "--no-ignore-permission-errors"

// Server specific
addSubCommand = "add"
Expand Down
8 changes: 5 additions & 3 deletions pkg/kopia/command/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package command

import "strconv"

type RestoreCommandArgs struct {
*CommandArgs
RootID string
Expand All @@ -27,7 +25,11 @@ type RestoreCommandArgs struct {
func Restore(cmdArgs RestoreCommandArgs) []string {
args := commonArgs(cmdArgs.CommandArgs, false)
args = args.AppendLoggable(restoreSubCommand, cmdArgs.RootID, cmdArgs.TargetPath)
args = args.AppendLoggableKV(ignorePermissionsError, strconv.FormatBool(cmdArgs.IgnorePermissionErrors))
if cmdArgs.IgnorePermissionErrors {
args = args.AppendLoggable(ignorePermissionsError)
} else {
args = args.AppendLoggable(noIgnorePermissionsError)
}

return stringSliceCommand(args)
}
4 changes: 2 additions & 2 deletions pkg/kopia/command/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (kRestore *KopiaRestoreTestSuite) TestRestoreCommands(c *C) {
}
return Restore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -58,7 +58,7 @@ func (kRestore *KopiaRestoreTestSuite) TestRestoreCommands(c *C) {
}
return Restore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors=true",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key restore snapshot-id target/path --ignore-permission-errors",
},
} {
cmd := strings.Join(tc.f(), " ")
Expand Down
6 changes: 5 additions & 1 deletion pkg/kopia/command/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ type SnapshotRestoreCommandArgs struct {
func SnapshotRestore(cmdArgs SnapshotRestoreCommandArgs) []string {
args := commonArgs(cmdArgs.CommandArgs, false)
args = args.AppendLoggable(snapshotSubCommand, restoreSubCommand, cmdArgs.SnapID, cmdArgs.TargetPath)
args = args.AppendLoggableKV(ignorePermissionsError, strconv.FormatBool(cmdArgs.IgnorePermissionErrors))
if cmdArgs.IgnorePermissionErrors {
args = args.AppendLoggable(ignorePermissionsError)
} else {
args = args.AppendLoggable(noIgnorePermissionsError)
}
if cmdArgs.SparseRestore {
args = args.AppendLoggable(sparseFlag)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kopia/command/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -91,7 +91,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=false",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --no-ignore-permission-errors",
},
{
f: func() []string {
Expand All @@ -104,7 +104,7 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *C) {
}
return SnapshotRestore(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors=true --write-sparse-files",
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot restore snapshot-id target/path --ignore-permission-errors --write-sparse-files",
},
{
f: func() []string {
Expand Down