From ba299aa71f330d7fe129d33b8a3ba9ba20c62595 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Thu, 14 Sep 2023 21:57:46 +0000 Subject: [PATCH] fix: incorrect remote taskfiles cache directory --- setup.go | 24 ++++++++++++++++++------ taskfile/read/node_file.go | 2 +- taskfile/read/taskfile.go | 12 ++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/setup.go b/setup.go index 51dc2913..fe723e68 100644 --- a/setup.go +++ b/setup.go @@ -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() @@ -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 } @@ -88,7 +101,6 @@ func (e *Executor) readTaskfile() error { if err != nil { return err } - e.Dir = filepath.Dir(e.Taskfile.Location) return nil } diff --git a/taskfile/read/node_file.go b/taskfile/read/node_file.go index 5cf25dd7..f7f8ed4e 100644 --- a/taskfile/read/node_file.go +++ b/taskfile/read/node_file.go @@ -25,7 +25,7 @@ func NewFileNode(uri string, opts ...NodeOption) (*FileNode, error) { } uri = d } - path, err := existsWalk(uri) + path, err := Exists(uri) if err != nil { return nil, err } diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index dcb78a62..6b8d8706 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -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 { @@ -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 @@ -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 }