Skip to content

Commit

Permalink
fix: incorrect remote taskfiles cache directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Sep 14, 2023
1 parent 0f134e4 commit 73f8906
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
24 changes: 18 additions & 6 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func (e *Executor) Setup() error {
if err := e.setCurrentDir(); err != nil {
return err
}
if err := e.readTaskfile(); err != nil {
if err := e.setupTempDir(); err != nil {
return err
}
if err := e.setupTempDir(); err != nil {
if err := e.readTaskfile(); err != nil {
return err
}
e.setupFuzzyModel()
Expand All @@ -55,19 +55,32 @@ func (e *Executor) Setup() error {
}

func (e *Executor) setCurrentDir() error {
// Default the directory to the current working directory
if e.Dir == "" {
wd, err := os.Getwd()
if err != nil {
return err
}
e.Dir = wd
} else if !filepath.IsAbs(e.Dir) {
abs, err := filepath.Abs(e.Dir)
}

// Ensure we have an absolute path
abs, err := filepath.Abs(e.Dir)
if err != nil {
return err
}
e.Dir = abs

// If no entrypoint is specified, we need to search for a taskfile
if e.Entrypoint == "" {
root, err := read.ExistsWalk(e.Dir)
if err != nil {
return err
}
e.Dir = abs
e.Dir = filepath.Dir(root)
e.Entrypoint = filepath.Base(root)
}

return nil
}

Expand All @@ -88,7 +101,6 @@ func (e *Executor) readTaskfile() error {
if err != nil {
return err
}
e.Dir = filepath.Dir(e.Taskfile.Location)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion taskfile/read/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewFileNode(uri string, opts ...NodeOption) (*FileNode, error) {
}
uri = d
}
path, err := existsWalk(uri)
path, err := ExistsWalk(uri)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions taskfile/read/taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func readTaskfile(
) (*taskfile.Taskfile, error) {
var b []byte
var err error

var cache *Cache

if node.Remote() {
cache, err = NewCache(tempDir)
if err != nil {
Expand Down Expand Up @@ -300,12 +300,12 @@ func Taskfile(
return _taskfile(node)
}

// exists will check if a file at the given path exists. If it does, it will
// Exists will check if a file at the given path Exists. If it does, it will
// return the path to it. If it does not, it will search the search for any
// files at the given path with any of the default Taskfile files names. If any
// of these match a file, the first matching path will be returned. If no files
// are found, an error will be returned.
func exists(path string) (string, error) {
func Exists(path string) (string, error) {
fi, err := os.Stat(path)
if err != nil {
return "", err
Expand All @@ -324,19 +324,19 @@ func exists(path string) (string, error) {
return "", errors.TaskfileNotFoundError{URI: path, Walk: false}
}

// existsWalk will check if a file at the given path exists by calling the
// ExistsWalk will check if a file at the given path exists by calling the
// exists function. If a file is not found, it will walk up the directory tree
// calling the exists function until it finds a file or reaches the root
// directory. On supported operating systems, it will also check if the user ID
// of the directory changes and abort if it does.
func existsWalk(path string) (string, error) {
func ExistsWalk(path string) (string, error) {
origPath := path
owner, err := sysinfo.Owner(path)
if err != nil {
return "", err
}
for {
fpath, err := exists(path)
fpath, err := Exists(path)
if err == nil {
return fpath, nil
}
Expand Down

0 comments on commit 73f8906

Please sign in to comment.