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

Change !os.IsNotExist to os.IsExist #787

Closed
wants to merge 1 commit into from

Conversation

@Smarticles101
Copy link
Member

@Smarticles101 Smarticles101 commented Dec 30, 2018

No description provided.

@Smarticles101
Copy link
Member Author

@Smarticles101 Smarticles101 commented Dec 30, 2018

Okay... So os.IsExist(err) != !os.IsNotExist(err). I thought the contrary but looking into it, I found this gist which explains it pretty well. Basically, the methods are just error checkers, they check for errors that are expected if a file exists or doesn't.

Since we query the file with Lstat, we expect the file to exist already, so it wouldn't throw an error if the file exists.

My fault for not testing it before I pushed it, but cool to learn that.

Loading

@@ -164,7 +164,7 @@ func runConfigure(configuration config.Config, flags *pflag.FlagSet) error {
workspace = config.DefaultWorkspaceDir(configuration)

// If it already exists don't clobber it with the default.
if _, err := os.Lstat(workspace); !os.IsNotExist(err) {
if _, err := os.Lstat(workspace); os.IsExist(err) {
Copy link
Contributor

@nywilken nywilken Dec 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.Lstat will return nil if the path exist. os.IsExist requires error to be ErrExist which is why file existence is being checked with !os.IsNotExist; Lstat will always return ErrNotExist if the path is not found otherwise nil (if there are no other errors).

Loading

Copy link
Member Author

@Smarticles101 Smarticles101 Dec 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I found that out lol. Thanks!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants