Skip to content

Conversation

@vipul-21
Copy link
Contributor

@vipul-21 vipul-21 commented Sep 7, 2022

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 deploy cmd for a file that was running continuously in the background.


if _, err := os.Stat(dest); err == nil || !os.IsNotExist(err) {
old_file_dest := dest + ".old"
os.RemoveAll(old_file_dest)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

@rbtr
Copy link
Collaborator

rbtr commented Sep 7, 2022

@vipul-21 as an aside from the content of this change, PRs are documentation. Please fill in the PR description so that

  1. any teammember will be able to gather the context necessary to review your change, and
  2. anyone in the future (ie you, in 6 months) will be able to look back at this PR and understand the problem you were attempting to fix, the proposed solution, and the context at this point in time.

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.
@timraymond maybe does the best job of this on the whole team, and this recent PR should be a good reference for you 🙂

@vipul-21
Copy link
Contributor Author

vipul-21 commented Sep 8, 2022

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.
Won't happen in the next PR. Thanks for the review, appreciate it :)

@vipul-21 vipul-21 requested a review from rbtr September 8, 2022 02:02
@rbtr
Copy link
Collaborator

rbtr commented Sep 8, 2022

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.
In the future, make feature branches instead of committing directly to master (even on your fork), and don't reuse branches that have already been merged for a new set of changes. It will make it easier for you to rebase your changes on top of the latest upstream changes if you keep them well separated.

@vipul-21
Copy link
Contributor Author

vipul-21 commented Sep 8, 2022

@rbtr There were 22 commits for rebase and had merge conflicts. So i created a separate branch with baseline as master and created the PR: #1586

Closing this one as that would be easier to review. Thanks Evan !

@vipul-21 vipul-21 reopened this Sep 8, 2022
Comment on lines 92 to 97
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)
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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

@vipul-21 vipul-21 requested a review from rbtr September 8, 2022 17:46
@vipul-21 vipul-21 requested a review from timraymond September 8, 2022 19:39
tamilmani1989
tamilmani1989 previously approved these changes Sep 8, 2022
@rbtr rbtr changed the title fix: cyclic dependency error while deploying through dropgz fix: file busy error while deploying through dropgz Sep 12, 2022
@vipul-21 vipul-21 merged commit 08408d7 into Azure:master Sep 12, 2022
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.

4 participants