mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 07:18:02 -05:00
```
make lint
kopia/tools/.tools/bin/golangci-lint --deadline 180s run | tee .linterr.txt
cli/command_snapshot_delete.go:5: File is not `goimports`-ed with -local github.com/kopia/kopia (goimports)
tests/end_to_end_test/end_to_end_test.go:303: Function 'TestSnapshotDelete' is too long (187 > 100) (funlen)
func TestSnapshotDelete(t *testing.T) {
tests/end_to_end_test/end_to_end_test.go:306:2: only one cuddle assignment allowed before range statement (wsl)
for _, tc := range []struct {
^
tests/end_to_end_test/end_to_end_test.go:517:4: only one cuddle assignment allowed before if statement (wsl)
if expectDeleteSucceeds {
^
tests/end_to_end_test/end_to_end_test.go:537:2: assignments should only be cuddled with other assignments (wsl)
line := lines[0]
^
tests/end_to_end_test/end_to_end_test.go:542:2: only one cuddle assignment allowed before if statement (wsl)
if typeVal != "policy" {
^
tests/end_to_end_test/end_to_end_test.go:558:2: assignments should only be cuddled with other assignments (wsl)
restoreDir := filepath.Join(e.dataDir, "restored")
^
tests/end_to_end_test/end_to_end_test.go:568:2: if statements should only be cuddled with assignments (wsl)
if got, want := len(si[0].snapshots), 1; got != want {
^
tests/end_to_end_test/end_to_end_test.go:571:2: assignments should only be cuddled with other assignments (wsl)
snapID := si[0].snapshots[0].snapshotID
^
tests/end_to_end_test/end_to_end_test.go:604:2: if statements should only be cuddled with assignments (wsl)
if len(fileInfo) != 0 {
^
cli/command_snapshot_delete.go:25:2: only one cuddle assignment allowed before if statement (wsl)
if err != nil {
^
cli/command_snapshot_delete.go:36:3: if statements should only be cuddled with assignments (wsl)
if labels["username"] != getUserName() {
^
```
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/repo/manifest"
|
|
)
|
|
|
|
var (
|
|
snapshotDeleteCommand = snapshotCommands.Command("delete", "Explicitly delete a snapshot by providing a snapshot ID.")
|
|
snapshotDeleteID = snapshotDeleteCommand.Arg("id", "Snapshot ID to be deleted").Required().String()
|
|
snapshotDeletePath = snapshotDeleteCommand.Flag("path", "Specify the path of the snapshot to be deleted").String()
|
|
snapshotDeleteIgnoreSource = snapshotDeleteCommand.Flag("unsafe-ignore-source", "Override the requirement to specify source info for the delete to succeed").Bool()
|
|
)
|
|
|
|
func runDeleteCommand(ctx context.Context, rep *repo.Repository) error {
|
|
if !*snapshotDeleteIgnoreSource && *snapshotDeletePath == "" {
|
|
return errors.New("path is required")
|
|
}
|
|
|
|
manifestID := manifest.ID(*snapshotDeleteID)
|
|
|
|
manifestMeta, err := rep.Manifests.GetMetadata(ctx, manifestID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
labels := manifestMeta.Labels
|
|
if labels["type"] != "snapshot" {
|
|
return errors.Errorf("snapshot ID provided (%v) did not reference a snapshot", manifestID)
|
|
}
|
|
|
|
if !*snapshotDeleteIgnoreSource {
|
|
if labels["hostname"] != getHostName() {
|
|
return errors.New("host name does not match for deleting requested snapshot ID")
|
|
}
|
|
|
|
if labels["username"] != getUserName() {
|
|
return errors.New("user name does not match for deleting requested snapshot ID")
|
|
}
|
|
|
|
if labels["path"] != *snapshotDeletePath {
|
|
return errors.New("path does not match for deleting requested snapshot ID")
|
|
}
|
|
}
|
|
|
|
return rep.Manifests.Delete(ctx, manifestID)
|
|
}
|
|
|
|
func init() {
|
|
addUserAndHostFlags(snapshotDeleteCommand)
|
|
snapshotDeleteCommand.Action(repositoryAction(runDeleteCommand))
|
|
}
|