Skip to content
Merged
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
11 changes: 7 additions & 4 deletions errors/errors_taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
// TaskfileNotFoundError is returned when no appropriate Taskfile is found when
// searching the filesystem.
type TaskfileNotFoundError struct {
URI string
Walk bool
AskInit bool
URI string
Walk bool
AskInit bool
OwnerChange bool
}

func (err TaskfileNotFoundError) Error() string {
var walkText string
if err.Walk {
if err.OwnerChange {
walkText = " (or any of the parent directories until ownership changed)."
} else if err.Walk {
walkText = " (or any of the parent directories)."
}
if err.AskInit {
Expand Down
17 changes: 10 additions & 7 deletions internal/fsext/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func SearchAll(entrypoint, dir string, possibleFilenames []string) ([]string, er
}
}
paths, err := SearchNPathRecursively(dir, possibleFilenames, -1)
if err != nil {
return nil, err
}
return append(entrypoints, paths...), nil
// The call to SearchNPathRecursively is ambiguous and may return
// os.ErrPermission if its search ends, however it may have still
// returned valid paths. Caller may choose to ignore that error.
return append(entrypoints, paths...), err
}

// SearchPath will check if a file at the given path exists or not. If it does,
Expand Down Expand Up @@ -188,9 +188,12 @@ func SearchNPathRecursively(path string, possibleFilenames []string, n int) ([]s
return nil, err
}

// Error if we reached the root directory and still haven't found a file
// OR if the user id of the directory changes
if path == parentPath || (parentOwner != owner) {
// If the user id of the directory changes indicate a permission error, otherwise
// the calling code will infer an error condition based on the accumulated
// contents of paths.
if parentOwner != owner {
return paths, os.ErrPermission
} else if path == parentPath {
return paths, nil
}

Expand Down
11 changes: 4 additions & 7 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/go-task/task/v3/internal/env"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/internal/fsext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/output"
"github.com/go-task/task/v3/internal/version"
Expand Down Expand Up @@ -60,12 +59,10 @@ func (e *Executor) getRootNode() (taskfile.Node, error) {
taskfile.WithCert(e.Cert),
taskfile.WithCertKey(e.CertKey),
)
if os.IsNotExist(err) {
return nil, errors.TaskfileNotFoundError{
URI: fsext.DefaultDir(e.Entrypoint, e.Dir),
Walk: true,
AskInit: true,
}
var taskNotFoundError errors.TaskfileNotFoundError
if errors.As(err, &taskNotFoundError) {
taskNotFoundError.AskInit = true
return nil, taskNotFoundError
}
if err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion taskfile/node_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ func NewFileNode(entrypoint, dir string, opts ...NodeOption) (*FileNode, error)
resolvedEntrypoint, err := fsext.Search(entrypoint, dir, DefaultTaskfiles)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: false}
if entrypoint == "" {
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: true}
} else {
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: false}
}
} else if errors.Is(err, os.ErrPermission) {
return nil, errors.TaskfileNotFoundError{URI: entrypoint, Walk: true, OwnerChange: true}
}
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions taskrc/taskrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"slices"
"strings"

"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/fsext"
"github.com/go-task/task/v3/taskrc/ast"
)
Expand Down Expand Up @@ -62,6 +63,9 @@ func GetConfig(dir string) (*ast.TaskRC, error) {
return config, err
}
entrypoints, err := fsext.SearchAll("", absDir, defaultTaskRCs)
if errors.Is(err, os.ErrPermission) {
err = nil
}
if err != nil {
return config, err
}
Expand Down
Loading