refactor(migration): use slices.Contains instead of local helper

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 18:08:01 +01:00
1 parent c2ef7a6c3b
commit c4a02daeff
1 file changed
+6 -13
+6 -13
View File
@@ -12,6 +12,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"slices"
"sort" "sort"
"strings" "strings"
"syscall" "syscall"
@@ -319,7 +320,7 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
} }
defer claim.Close() defer claim.Close()
s.Config = c s.Config = c
if !contains(s.Notes, SnapshotIdentityNote) { if !slices.Contains(s.Notes, SnapshotIdentityNote) {
s.Notes = append(s.Notes, SnapshotIdentityNote) s.Notes = append(s.Notes, SnapshotIdentityNote)
if err = SaveState(abs, s); err != nil { if err = SaveState(abs, s); err != nil {
return err return err
@@ -381,7 +382,7 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
for i := range s.Snapshots { for i := range s.Snapshots {
if s.Snapshots[i].Done { if s.Snapshots[i].Done {
snap := &s.Snapshots[i] snap := &s.Snapshots[i]
if !contains(targetNames, snap.Name) { if !slices.Contains(targetNames, snap.Name) {
return fmt.Errorf("completed target snapshot %q disappeared", snap.Name) return fmt.Errorf("completed target snapshot %q disappeared", snap.Name)
} }
info, err := snapshotDetails(ctx, dst, snap.Name) info, err := snapshotDetails(ctx, dst, snap.Name)
@@ -391,7 +392,7 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
if info.CreatedAt != snap.TargetCreatedAt { if info.CreatedAt != snap.TargetCreatedAt {
return fmt.Errorf("completed target snapshot %q was replaced", snap.Name) return fmt.Errorf("completed target snapshot %q was replaced", snap.Name)
} }
if contains(inspection.SourceSnapshots, snap.Name) { if slices.Contains(inspection.SourceSnapshots, snap.Name) {
info, err = snapshotDetails(ctx, src, snap.Name) info, err = snapshotDetails(ctx, src, snap.Name)
if err != nil { if err != nil {
return err return err
@@ -480,7 +481,7 @@ func (e Engine) transfer(ctx context.Context, src, dst ceph, target, statePath s
if err != nil { if err != nil {
return err return err
} }
if !contains(names, snap.Name) { if !slices.Contains(names, snap.Name) {
if !snap.Owned || snap.CreatedAt != "" { if !snap.Owned || snap.CreatedAt != "" {
return fmt.Errorf("source snapshot %q disappeared before transfer", snap.Name) return fmt.Errorf("source snapshot %q disappeared before transfer", snap.Name)
} }
@@ -508,7 +509,7 @@ func (e Engine) transfer(ctx context.Context, src, dst ceph, target, statePath s
return err return err
} }
aware, isNative := e.Transport.(RoundTransport) aware, isNative := e.Transport.(RoundTransport)
existed := contains(targetNames, snap.Name) existed := slices.Contains(targetNames, snap.Name)
if isNative { if isNative {
round := Round{SourcePath: from, TargetPath: target, Name: snap.Name, StatePath: statePath, BaseName: s.LiveSnapshot} round := Round{SourcePath: from, TargetPath: target, Name: snap.Name, StatePath: statePath, BaseName: s.LiveSnapshot}
if s.LiveSnapshot != "" { if s.LiveSnapshot != "" {
@@ -591,11 +592,3 @@ func (e Engine) transfer(ctx context.Context, src, dst ceph, target, statePath s
e.log("snapshot=%s: verified and committed", snap.Name) e.log("snapshot=%s: verified and committed", snap.Name)
return nil return nil
} }
func contains(names []string, name string) bool {
for _, n := range names {
if n == name {
return true
}
}
return false
}