Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check if config file exists. Directory was detected as file #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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