From 5a2520e3b1e5c6b2ef6c89dc2f2ae5da0aea3cf3 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 10 Mar 2025 19:07:53 +0100 Subject: [PATCH] Fix deleting by not deleting at all --- instruction.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/instruction.go b/instruction.go index a8744af..5b94134 100644 --- a/instruction.go +++ b/instruction.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "path/filepath" - "slices" "strings" "gopkg.in/yaml.v3" @@ -281,8 +280,8 @@ func ParseYAMLFile(filename, workdir string) ([]LinkInstruction, error) { config.Links = instructions } - toRemove := []int{} - for i, link := range config.Links { + expanded := []LinkInstruction{} + for _, link := range config.Links { if strings.Contains(link.Source, "*") { LogSource("Expanding wildcard source %s in YAML file %s", link.Source, filename) newlinks, err := ExpandWildcard(link.Source, workdir, link.Target) @@ -297,17 +296,14 @@ func ParseYAMLFile(filename, workdir string) ([]LinkInstruction, error) { } LogInfo("Expanded wildcard source %s in YAML file %s to %d links", FormatSourcePath(link.Source), FormatSourcePath(filename), len(newlinks)) - config.Links = append(config.Links, newlinks...) - toRemove = append(toRemove, i) + expanded = append(expanded, newlinks...) + } else { + expanded = append(expanded, link) } } - for i := len(toRemove) - 1; i >= 0; i-- { - config.Links = slices.Delete(config.Links, toRemove[i], 1) - } - - for i := range config.Links { - link := &config.Links[i] + for i := range expanded { + link := &expanded[i] link.Tidy() link.Source, _ = ConvertHome(link.Source) @@ -316,12 +312,12 @@ func ParseYAMLFile(filename, workdir string) ([]LinkInstruction, error) { link.Target = NormalizePath(link.Target, workdir) // If Delete is true, Force must also be true - if config.Links[i].Delete { - config.Links[i].Force = true + if link.Delete { + link.Force = true } } - return config.Links, nil + return expanded, nil } func ExpandWildcard(source, workdir, target string) (links []LinkInstruction, err error) {