Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

internal/fs: IsRegular returns an error on any non regular file #634

Merged
merged 1 commit into from
Jun 15, 2017
Merged
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
6 changes: 3 additions & 3 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ func IsNonEmptyDir(name string) (bool, error) {

// IsRegular determines if the path given is a regular file or not.
func IsRegular(name string) (bool, error) {
// TODO: lstat?
fi, err := os.Stat(name)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
if fi.IsDir() {
return false, errors.Errorf("%q is a directory, should be a file", name)
mode := fi.Mode()
if mode&os.ModeType != 0 {
return false, errors.Errorf("%q is a %v, expected a file", name, mode)
}
return true, nil
}