Hallucinate a fix to recurse using doublestar
This commit is contained in:
81
main.go
81
main.go
@@ -7,7 +7,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
@@ -20,7 +19,6 @@ const ImportantColor = BRed
|
||||
const DefaultColor = Reset
|
||||
const PathColor = Green
|
||||
|
||||
var FileRegex, _ = regexp.Compile(`sync\.ya?ml$`)
|
||||
var programName = os.Args[0]
|
||||
var undo = false
|
||||
|
||||
@@ -145,58 +143,49 @@ func ReadFromFilesRecursively(input string, output chan *LinkInstruction, status
|
||||
|
||||
files := make(chan string, 128)
|
||||
fileStatus := make(chan error)
|
||||
var wg sync.WaitGroup
|
||||
go GetSyncFilesRecursively(input, files, fileStatus)
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(files)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
err, ok := <-fileStatus
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
LogError("Failed to get sync files recursively: %v", err)
|
||||
status <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Collect all files first
|
||||
var syncFiles []string
|
||||
for {
|
||||
file, ok := <-files
|
||||
if !ok {
|
||||
LogInfo("No more files to process")
|
||||
break
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
LogInfo(file)
|
||||
file = NormalizePath(file, workdir)
|
||||
LogInfo("Processing file: %s", FormatPathValue(file))
|
||||
syncFiles = append(syncFiles, file)
|
||||
}
|
||||
|
||||
// This "has" to be done because instructions are resolved in relation to cwd
|
||||
fileDir := FileRegex.FindStringSubmatch(file)
|
||||
if fileDir == nil {
|
||||
LogError("Failed to extract directory from %s", FormatSourcePath(file))
|
||||
return
|
||||
}
|
||||
LogInfo("Changing directory to %s (for %s)",
|
||||
FormatPathValue(fileDir[1]),
|
||||
FormatPathValue(file))
|
||||
err := os.Chdir(fileDir[1])
|
||||
if err != nil {
|
||||
LogError("Failed to change directory to %s: %v",
|
||||
FormatSourcePath(fileDir[1]), err)
|
||||
return
|
||||
}
|
||||
ReadFromFile(file, output, status, false)
|
||||
// Don't return directory, stay where we are
|
||||
os.Chdir(workdir)
|
||||
}()
|
||||
// Check for errors from file search
|
||||
for {
|
||||
err, ok := <-fileStatus
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
LogError("Failed to get sync files recursively: %v", err)
|
||||
status <- err
|
||||
}
|
||||
}
|
||||
|
||||
// Process each file
|
||||
for _, file := range syncFiles {
|
||||
file = NormalizePath(file, workdir)
|
||||
LogInfo("Processing file: %s", FormatPathValue(file))
|
||||
|
||||
// Change to the directory containing the sync file
|
||||
fileDir := filepath.Dir(file)
|
||||
originalDir, _ := os.Getwd()
|
||||
err := os.Chdir(fileDir)
|
||||
if err != nil {
|
||||
LogError("Failed to change directory to %s: %v", FormatSourcePath(fileDir), err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Read and process the file
|
||||
ReadFromFile(file, output, status, false)
|
||||
|
||||
// Return to original directory
|
||||
os.Chdir(originalDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user