Skip to content

Commit

Permalink
cmd: fix printing an error when writing to directory but it doesn't e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
tdewolff committed Jan 26, 2024
1 parent d302269 commit 8b9a65f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
5 changes: 1 addition & 4 deletions cmd/minify/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (
"github.com/matryer/try"
)

// IsDir returns true if the passed string looks like it specifies a directory, false otherwise.
// IsDir returns whether the path is a directory.
func IsDir(dir string) bool {
if 0 < len(dir) && dir[len(dir)-1] == os.PathSeparator {
return true
}
info, err := os.Lstat(dir)
return err == nil && info.Mode().IsDir() && info.Mode()&os.ModeSymlink == 0
}
Expand Down
17 changes: 7 additions & 10 deletions cmd/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,14 @@ func run() int {
// set output file or directory, empty means stdout
dirDst := false
if output != "" {
dirDst = IsDir(output)
if !dirDst {
if 1 < len(inputs) && !bundle {
Error.Printf("stat %v: no such file or directory\n", output)
return 1
} else if len(inputs) == 1 {
if info, err := os.Lstat(inputs[0]); err == nil && !bundle && info.Mode().IsDir() && info.Mode()&os.ModeSymlink == 0 {
dirDst = true
}
}
if 0 < len(output) && output[len(output)-1] == os.PathSeparator {
dirDst = true
} else if !bundle && 1 < len(inputs) {
dirDst = true
} else if !bundle && len(inputs) == 1 && IsDir(inputs[0]) {
dirDst = true
}

if dirDst && bundle {
Error.Println("--bundle requires destination to be stdout or a file")
return 1
Expand Down

0 comments on commit 8b9a65f

Please sign in to comment.