Skip to content

Commit

Permalink
u-root.go: test for relative paths with os.Stat()
Browse files Browse the repository at this point in the history
The current u-root has gotten a little frustrating
with messages like this:
22:35:48 "cpu/cmds/cpud/" is not a valid path, allowed are only existing relative or absolute file paths!

Which is not only wrong, in this case: the path cpu/cmds/cpud does exist and is relative,
but very confusing when you use ./cpud/cmds/cpud instead.

Do the easy thing with the arg to validateArg first: just os.Stat().

If it fails, the more complex test can be used, but if it succeeds, time is saved.

Signed-off-by: Ronald G. Minnich <[email protected]>
  • Loading branch information
rminnich authored and probot-auto-merge[bot] committed Aug 2, 2022
1 parent fe93f28 commit 0458169
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions u-root.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ func Main(l ulog.Logger, buildOpts *gbbgolang.BuildOpts) error {
}

func validateArg(arg string) bool {
// Do the simple thing first: stat the path.
// This saves incorrect diagnostics when the
// path is a perfectly valid relative path.
if _, err := os.Stat(arg); err == nil {
return true
}
if !checkPrefix(arg) {
paths, err := filepath.Glob(arg)
if err != nil {
Expand Down

0 comments on commit 0458169

Please sign in to comment.