build: modernize with "go fix -slicescontains": use slices.Contains

This commit is contained in:
Nick Craig-Wood
2026-08-21 12:23:31 +01:00
parent 237719bb8d
commit 9f9fd82923
3 changed files with 8 additions and 14 deletions
+2 -6
View File
@@ -4,6 +4,7 @@ package api
import (
"encoding/xml"
"regexp"
"slices"
"strconv"
"strings"
"sync"
@@ -107,12 +108,7 @@ func (p *Prop) StatusOK() bool {
if len(p.Status) == 0 {
return true
}
for _, statusStr := range p.Status {
if parseStatus2XX.MatchString(statusStr) {
return true
}
}
return false
return slices.ContainsFunc(p.Status, parseStatus2XX.MatchString)
}
// Hashes returns a map of all checksums - may be nil
+3 -4
View File
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"path"
"slices"
"strings"
"github.com/mholt/archives"
@@ -219,10 +220,8 @@ func ArchiveExtract(ctx context.Context, dst fs.Fs, dstDir string, src fs.Fs, sr
func destPath(nameInArchive, dstDir string) (string, error) {
remote := strings.TrimPrefix(nameInArchive, "./")
isSeparator := func(r rune) bool { return r == '/' || r == '\\' }
for _, segment := range strings.FieldsFunc(remote, isSeparator) {
if segment == ".." {
return "", fmt.Errorf("refusing to extract archive entry %q with a %q path component", nameInArchive, "..")
}
if slices.Contains(strings.FieldsFunc(remote, isSeparator), "..") {
return "", fmt.Errorf("refusing to extract archive entry %q with a %q path component", nameInArchive, "..")
}
if remote == "" {
return "", nil
+3 -4
View File
@@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"time"
@@ -682,10 +683,8 @@ func UnsetRemote(name string, keys ...string) (removed []string, err error) {
if GetValue(name, "type") == "" {
return nil, fmt.Errorf("remote %q doesn't exist", name)
}
for _, key := range keys {
if key == "type" {
return nil, errors.New(`can't unset the "type" of a remote - use "config delete" to remove the whole remote`)
}
if slices.Contains(keys, "type") {
return nil, errors.New(`can't unset the "type" of a remote - use "config delete" to remove the whole remote`)
}
for _, key := range keys {
if FileDeleteKey(name, key) {