Fix deleting by not deleting at all

This commit is contained in:
2025-03-10 19:07:53 +01:00
parent 12d71dba1c
commit 5a2520e3b1

View File

@@ -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) {