Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/ema/pets

go 1.19

require github.com/hashicorp/logutils v1.0.0 // indirect
require (
github.com/facebookgo/symwalk v0.0.0-20150726040526-42004b9f3222 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/facebookgo/symwalk v0.0.0-20150726040526-42004b9f3222 h1:ivxAxcE9py2xLAqpcEwN7sN711aLfEWgh3cY0aha7uY=
github.com/facebookgo/symwalk v0.0.0-20150726040526-42004b9f3222/go.mod h1:PgrCjL2+FgkITqxQI+erRTONtAv4JkpOzun5ozKW/Jg=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
15 changes: 12 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"path/filepath"
"regexp"
"strings"

"github.com/facebookgo/symwalk"
)

// Because it is important to know when enough is enough.
Expand Down Expand Up @@ -126,7 +128,7 @@ func ParseFiles(directory string) ([]*PetsFile, error) {

log.Printf("[DEBUG] using configuration directory '%s'\n", directory)

err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
err := symwalk.Walk(directory, func(path string, info os.FileInfo, err error) error {
// This function is called once for each file in the Pets configuration
// directory
if err != nil {
Expand Down Expand Up @@ -159,10 +161,17 @@ func ParseFiles(directory string) ([]*PetsFile, error) {
// is the source path. Every long journey begins with a single step!
pf := NewPetsFile()

// Evaluate the symlinks, to simplify checking whether a symlink
// we created points to the file it should
direct, err := filepath.EvalSymlinks(path)
if err != nil {
return err
}

// Get absolute path to the source. Technically we would be fine with a
// relative path too, but it's good to remove abiguity. Plus absolute
// relative path too, but it's good to remove ambiguity. Plus absolute
// paths make things easier in case we have to create a symlink.
abs, err := filepath.Abs(path)
abs, err := filepath.Abs(direct)
if err != nil {
return err
}
Expand Down