mirror of
https://github.com/restic/restic.git
synced 2026-09-19 02:37:58 +00:00
Apply go fix -slicescontains ./...
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -304,10 +305,8 @@ func (opts BackupOptions) Check(gopts global.Options, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filesFrom := append(append(opts.FilesFrom, opts.FilesFromVerbatim...), opts.FilesFromRaw...)
|
filesFrom := append(append(opts.FilesFrom, opts.FilesFromVerbatim...), opts.FilesFromRaw...)
|
||||||
for _, filename := range filesFrom {
|
if slices.Contains(filesFrom, "-") {
|
||||||
if filename == "-" {
|
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
|
||||||
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -630,13 +631,7 @@ func linkEqual(source, dest []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range source {
|
for i := range source {
|
||||||
found := false
|
found := slices.Contains(dest, source[i])
|
||||||
for j := range dest {
|
|
||||||
if source[i] == dest[j] {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
if !found {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -49,13 +50,7 @@ func validateCatArgs(args []string) error {
|
|||||||
return errors.Fatal("type not specified")
|
return errors.Fatal("type not specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
validType := false
|
validType := slices.Contains(catAllowedCmds, args[0])
|
||||||
for _, v := range catAllowedCmds {
|
|
||||||
if v == args[0] {
|
|
||||||
validType = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !validType {
|
if !validType {
|
||||||
return errors.Fatalf("invalid type %q, must be one of [%s]", args[0], strings.Join(catAllowedCmds, "|"))
|
return errors.Fatalf("invalid type %q, must be one of [%s]", args[0], strings.Join(catAllowedCmds, "|"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -339,13 +340,7 @@ func removePacksExcept(gopts global.Options, t testing.TB, keep restic.IDSet, re
|
|||||||
}
|
}
|
||||||
|
|
||||||
func includes(haystack []string, needle string) bool {
|
func includes(haystack []string, needle string) bool {
|
||||||
for _, s := range haystack {
|
return slices.Contains(haystack, needle)
|
||||||
if s == needle {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSnapshotMap(t testing.TB, gopts global.Options) map[string]struct{} {
|
func loadSnapshotMap(t testing.TB, gopts global.Options) map[string]struct{} {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -174,12 +175,7 @@ func (sn *Snapshot) RemoveTags(removeTags []string) (changed bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sn *Snapshot) hasTag(tag string) bool {
|
func (sn *Snapshot) hasTag(tag string) bool {
|
||||||
for _, snTag := range sn.Tags {
|
return slices.Contains(sn.Tags, tag)
|
||||||
if tag == snTag {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasTags returns true if the snapshot has all the tags in l.
|
// HasTags returns true if the snapshot has all the tags in l.
|
||||||
@@ -240,13 +236,7 @@ func (sn *Snapshot) HasHostname(hostnames []string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hostname := range hostnames {
|
return slices.Contains(hostnames, sn.Hostname)
|
||||||
if sn.Hostname == hostname {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snapshots is a list of snapshots.
|
// Snapshots is a list of snapshots.
|
||||||
|
|||||||
Reference in New Issue
Block a user