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

Fixed bingo get fails on Windows #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

melvinmurvie
Copy link

This PR is to make sure opened files are closed immediately (instead of at defer) if we don't need it anymore.

On Windows an error occurs when we try to rename from/to an opened files. Calling os.Rename(old, new) we should make sure to close both old and new files (if new is existed and opened).

Fixes #127

@melvinmurvie melvinmurvie marked this pull request as draft November 7, 2024 09:43
@melvinmurvie melvinmurvie marked this pull request as ready for review November 7, 2024 09:45
Copy link
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks so much for helping!

I gave some suggestions on a bit cleaner approach, but good progress and thanks for approaching this! 💪🏽

@@ -200,7 +200,9 @@ func get(ctx context.Context, logger *log.Logger, c getConfig, rawTarget string)
if err != nil {
return errors.Wrapf(err, "found unparsable mod file %v. Uninstall it first via get %v@none or fix it manually.", e, name)
}
defer errcapture.Do(&err, mf.Close, "close")
if err := mf.Close(); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks! Can we ensure we don't use mf variable after Close? Here we can do easily with dpkg := *mf.DirectPackage() and then close and then append to target (:

@@ -260,7 +262,9 @@ func get(ctx context.Context, logger *log.Logger, c getConfig, rawTarget string)
if err != nil {
return errors.Wrapf(err, "found unparsable mod file %v. Uninstall it first via get %v@none or fix it manually.", e, name)
}
defer errcapture.Do(&err, mf.Close, "close")
if err := mf.Close(); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

ditto. We can't use mf after Close even if by accident in this code we can.

@@ -652,6 +663,12 @@ func getPackage(ctx context.Context, logger *log.Logger, c installPackageConfig,
return err
}

// We have close it once here so the defer func does not need to close it again.
closed = true
if err := tmpModFile.Close(); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Same here, it's not acceptable to use tmpModFile var that is closed. It might work by accident now, but will cause surprises later on.

Why not closing right before os.Rename (and saving tmpModFile fileapath to variable?)

@melvinmurvie
Copy link
Author

Thanks so much for helping!

I gave some suggestions on a bit cleaner approach, but good progress and thanks for approaching this! 💪🏽

@bwplotka Thanks for the suggestions! I've already made the changes, please take a look and let me know if there's anything else need to improve! 🙏🏽

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.

bingo get fails on Windows: bingo.tmp.mod is being used by another process
2 participants