-
Notifications
You must be signed in to change notification settings - Fork 260
fix: file busy error while deploying through dropgz #1582
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
Conversation
dropgz/pkg/embed/payload.go
Outdated
|
|
||
| if _, err := os.Stat(dest); err == nil || !os.IsNotExist(err) { | ||
| old_file_dest := dest + ".old" | ||
| os.RemoveAll(old_file_dest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if this remove fails? ignoring the returned error is 👎🏼, if we really don't care we should _ = os.RemoveAll(old_file_dest) it to positively indicate that it doesn't matter.
but if we don't care if this errors...do we even need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to add an error handler than to silently ignore it. So will be adding it in the next update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why or why not we should handle this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be handling the error in this case, Removeall will return nil if the path does not exists which is good for us for the first time. But there can be other Patherror returned while removing the dest. If we ignore it, then the next part of the code that renames the files will be errored out as well because the old file was not removed in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why dont we use os.Remove since we are removing single file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first the file won't be present, so os.Remove will error out.
|
@vipul-21 as an aside from the content of this change, PRs are documentation. Please fill in the PR description so that
There should have been a description template prepulated when you opened the PR, so I can only assume that you intentionally deleted that instead of filling it in with useful information. This same thing applies to your commit history and messages - the commit history on this PR is an unreadable mess, but it should provide documentation which help the reader understand what changes are being made and why. |
|
Thank @rbtr for the review. I'll add the description for the PR. Regarding the commit messages, git is tracking everything since start for my PR, even though those comments are already merged. I need to make amends to my fork master branch because the diff only shows the last commit I made, but the PR includes all the commits so far. |
|
The commit history needs to be fixed in this PR. The docs for git rebase and git cherry-pick will help you. Do not update with merge commits. The commit history should contain only the commits related to this change. |
dropgz/pkg/embed/payload.go
Outdated
| if err = os.RemoveAll(old_file_dest); err != nil { | ||
| return errors.Wrapf(err, "not able to remove the %s", &old_file_dest) | ||
| } | ||
| if err = os.Rename(dest, old_file_dest); err != nil { | ||
| return errors.Wrapf(err, "not able to rename the %s to %s", dest, old_file_dest) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the os.RemoveAll is unnecessary - os.Rename will remove the file at dest, if it exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first the file won't be present, so os.Remove will error out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't say anything about os.Remove
Reason for Change:
This is a fix for the cyclic dependency in the dropgz deploy subcommand. The deploy command is trying to write a file that is already being executed by some other program.
This change renames the current dest as old one ( deleting the old dest if it exists) and then try to write the new content to the dest.
Requirements:
Notes:
Tested the change locally by trying to use the
deploycmd for a file that was running continuously in the background.