Skip to content

Don't error maintenance commands on missing library clone folder #125

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

Merged
merged 2 commits into from
May 27, 2022
Merged

Don't error maintenance commands on missing library clone folder #125

merged 2 commits into from
May 27, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented May 27, 2022

The maintenance commands libraries-repository-engine modify and libraries-repository-engine remove are designed in a conservative manner where the operation is to be immediately halted and all affected data restored if any unexpected conditions are encountered.

Previously, the absence of a library's "Git clone folder" targeted for deletion was considered such an unexpected condition.

Investigation of some failures during the course of maintenance operations revealed that this folder may be absent under certain expected conditions.

The reason is that the "sync" operation deletes the folder after a failed git fetch operation before trying a git clone of a fresh copy of the repository. If that retry fails, the result is that there is no longer a "Git clone folder" for that library on Arduino's server.

// Clone repository
repo, err := libraries.CloneOrFetch(repoMetadata, repoFolder)
if err != nil {
logger.Printf("Error fetching repository: %s", err)
logger.Printf("Removing clone and trying again")
os.RemoveAll(repoFolder)
repo, err = libraries.CloneOrFetch(repoMetadata, repoFolder)
if err != nil {
logger.Printf("Error fetching repository: %s", err)
logger.Printf("Leaving...")
return
}
}

So the absence of this folder should not be treated as cause for the maintenance command to fail. Instead, the command should warn the user (i.e., the library registry backend maintainer) of the situation and then carry on with the operation.

per1234 added 2 commits May 27, 2022 06:48
Both the `libraries-repository-engine remove` and `libraries-repository-engine modify --repo-url` commands delete the
library's "Git clone folder". Previously, the code for doing this was repeated verbatim for each command.

At the time the code was written, this was considered reasonable since it was not a lot of code and the architectural
structure of the module does not provide an obvious location for a shared function containing that code. However, it is
now planned to add additional code, which tips the balance toward a function.

This also enables increasing the unit test coverage of the code.
The maintenance commands `libraries-repository-engine modify` and `libraries-repository-engine remove` are designed in a
conservative manner where the operation is to be immediately halted and all affected data restored if any unexpected
conditions are encountered.

Previously, the absence of a library's "Git clone folder" targeted for deletion was considered such an unexpected
condition.

Investigation of some failures during the course of maintenance operations revealed that this folder may be absent under
certain expected conditions.

The reason is that the "sync" operation deletes the folder after a failed `git fetch` operation before trying a
`git clone` of a fresh copy of the repository. If that retry fails, the result is that there is no longer a
"Git clone folder" for that library on Arduino's server.

So the absence of this folder should not be treated as cause for the maintenance command to fail. Instead, the command
should warn the user of the situation and then carry on with the operation.
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels May 27, 2022
@per1234 per1234 requested a review from umbynos May 27, 2022 14:05
@per1234 per1234 self-assigned this May 27, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #125 (893e86f) into main (4fd9cf7) will increase coverage by 0.95%.
The diff coverage is 44.00%.

@@            Coverage Diff             @@
##             main     #125      +/-   ##
==========================================
+ Coverage   41.58%   42.54%   +0.95%     
==========================================
  Files          26       26              
  Lines        1450     1455       +5     
==========================================
+ Hits          603      619      +16     
+ Misses        790      775      -15     
- Partials       57       61       +4     
Flag Coverage Δ
unit 42.54% <44.00%> (+0.95%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/command/modify/modify.go 0.00% <0.00%> (ø)
internal/command/remove/remove.go 0.00% <0.00%> (ø)
internal/libraries/repoclone.go 45.05% <47.82%> (+0.93%) ⬆️
internal/feedback/feedback.go 31.25% <0.00%> (+31.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fd9cf7...893e86f. Read the comment docs.

@per1234 per1234 merged commit a76f7ee into arduino:main May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants