Have claude do some completely retarded shit

This commit is contained in:
2025-11-11 13:00:04 +01:00
parent ade7c4d2b2
commit d8de4717e2
5 changed files with 339 additions and 50 deletions

View File

@@ -143,11 +143,8 @@ func ParseInstruction(line, workdir string) (LinkInstruction, error) {
}
instruction.Tidy()
instruction.Source, _ = ConvertHome(instruction.Source)
instruction.Target, _ = ConvertHome(instruction.Target)
instruction.Source = NormalizePath(instruction.Source, workdir)
instruction.Target = NormalizePath(instruction.Target, workdir)
instruction.Source = ResolvePath(instruction.Source, workdir)
// Target should remain relative for YAML parsing - it gets resolved when creating the link
return instruction, nil
}
@@ -290,10 +287,8 @@ func ParseYAMLFile(filename, workdir string) ([]LinkInstruction, error) {
for i := range processedInstructions {
link := &processedInstructions[i]
link.Tidy()
link.Source, _ = ConvertHome(link.Source)
link.Target, _ = ConvertHome(link.Target)
link.Source = NormalizePath(link.Source, workdir)
link.Target = NormalizePath(link.Target, workdir)
link.Source = ResolvePath(link.Source, workdir)
// Target should remain relative for YAML parsing - it gets resolved when creating the link
// If Delete is true, Force must also be true
if link.Delete {
@@ -339,17 +334,9 @@ func preprocessInstructions(instructions []LinkInstruction, filename, workdir st
// loadFromReference loads instructions from a referenced file
func loadFromReference(fromFile, currentFile, workdir string, visited map[string]bool) ([]LinkInstruction, error) {
// First convert home directory if it starts with ~
fromPath, err := ConvertHome(fromFile)
if err != nil {
return nil, fmt.Errorf("error converting home directory: %w", err)
}
// Convert relative paths to absolute paths based on the current file's directory
if !filepath.IsAbs(fromPath) {
currentDir := filepath.Dir(currentFile)
fromPath = filepath.Join(currentDir, fromPath)
}
// Use ResolvePath to properly handle tilde expansion and relative paths
currentDir := filepath.Dir(currentFile)
fromPath := ResolvePath(fromFile, currentDir)
// Normalize the path
fromPath = filepath.Clean(fromPath)
@@ -361,13 +348,22 @@ func loadFromReference(fromFile, currentFile, workdir string, visited map[string
// expandGlobs expands glob patterns in a single instruction
func expandGlobs(instr LinkInstruction, filename, workdir string) ([]LinkInstruction, error) {
// Convert home directory (~) before expanding pattern
convertedSource, err := ConvertHome(instr.Source)
if err != nil {
return nil, fmt.Errorf("error converting home directory in source %s: %w", instr.Source, err)
// Check if the source contains glob pattern characters
source := instr.Source
hasGlob := strings.ContainsAny(source, "*?[") || strings.Contains(source, "**")
if !hasGlob {
// No glob pattern - create single instruction for the file
LogSource("Processing single file source %s in YAML file %s", source, filename)
convertedSource := ResolvePath(source, workdir)
instruction := instr
instruction.Source = convertedSource
return []LinkInstruction{instruction}, nil
}
LogSource("Expanding pattern source %s in YAML file %s", convertedSource, filename)
// Has glob pattern - expand it
LogSource("Expanding pattern source %s in YAML file %s", source, filename)
convertedSource := ResolvePath(source, workdir)
newlinks, err := ExpandPattern(convertedSource, workdir, instr.Target)
if err != nil {
return nil, err
@@ -430,10 +426,8 @@ func parseYAMLFileRecursive(filename, workdir string, visited map[string]bool) (
for i := range processedInstructions {
link := &processedInstructions[i]
link.Tidy()
link.Source, _ = ConvertHome(link.Source)
link.Target, _ = ConvertHome(link.Target)
link.Source = NormalizePath(link.Source, workdir)
link.Target = NormalizePath(link.Target, workdir)
link.Source = ResolvePath(link.Source, workdir)
// Target should remain relative for YAML parsing - it gets resolved when creating the link
// If Delete is true, Force must also be true
if link.Delete {
@@ -445,17 +439,21 @@ func parseYAMLFileRecursive(filename, workdir string, visited map[string]bool) (
}
func ExpandPattern(source, workdir, target string) (links []LinkInstruction, err error) {
// Convert home directory (~) before splitting pattern
source, err = ConvertHome(source)
if err != nil {
return nil, fmt.Errorf("error converting home directory in source %s: %w", source, err)
}
// Normalize path to convert backslashes to forward slashes before pattern processing
source = NormalizePath(source, workdir)
// First convert backslashes to forward slashes for pattern matching
source = filepath.ToSlash(source)
// Split pattern to get static and pattern parts
static, pattern := doublestar.SplitPattern(source)
// Only resolve the static part, NOT the pattern part
if static == "" || static == "." {
static = workdir
} else {
// Resolve the static part properly (handle tilde, make absolute)
static = ResolvePath(static, workdir)
}
// Normalize the static part
static = NormalizePath(static, workdir)
LogInfo("Static part: %s", static)
LogInfo("Pattern part: %s", pattern)