Skip to content

Conversation

@dol
Copy link

@dol dol commented Apr 5, 2017

'os.Stat' checks if a file or directory exists. By adding an
additional check (mode) the distinction could be made.

By checking !os.IsNotExist(err) could also go wrong, due to other types of error that can occur. It's best IMHO to check if there is no error.

E.g on Linux:

mkdir -p ~/.config/vendor/app/foobar
...
configDirs := configdir.New("vendor", "app")

config := configDirs.QueryFolders(configdir.Global)
if config.Exists("foobar") {
  // Path ~/.config/vendor/app/foobar is a directory
  fmt.Println("file exists")
}
// 

'os.Stat' checks if a file or directory exists. By adding an
additional check (mode) the distinction could be made.
@andreyvit
Copy link

I don't think Exists is meant to only check for file existence. In pretty much every language, similarly-named functions return true for both files and directories. (Also, IsRegular is too strict; what if it's a symlink? I regularly symlink config files into my configuration Git repo.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants