Skip to content

Commit

Permalink
Don't error maintenance commands on missing library clone folder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
per1234 committed May 27, 2022
1 parent 01a027b commit 893e86f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions internal/libraries/repoclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/arduino/go-paths-helper"
"github.com/arduino/libraries-repository-engine/internal/backup"
"github.com/arduino/libraries-repository-engine/internal/configuration"
"github.com/arduino/libraries-repository-engine/internal/feedback"
"github.com/arduino/libraries-repository-engine/internal/libraries/db"

"fmt"
Expand Down Expand Up @@ -145,12 +146,21 @@ func BackupAndDeleteGitClone(config *configuration.Config, repoMeta *Repo) error
return err
}
gitClonePath := paths.New(config.GitClonesFolder, gitCloneSubfolder)

if err := backup.Backup(gitClonePath); err != nil {
return fmt.Errorf("While backing up library's Git clone: %w", err)
// The library's clone folder may be removed by the sync process under expected circumstances.
// So its absence does not necessarily imply a problem.
gitClonePathExists, err := gitClonePath.ExistCheck()
if err != nil {
return err
}
if err := gitClonePath.RemoveAll(); err != nil {
return fmt.Errorf("While removing library Git clone: %s", err)
if gitClonePathExists {
if err := backup.Backup(gitClonePath); err != nil {
return fmt.Errorf("While backing up library's Git clone: %w", err)
}
if err := gitClonePath.RemoveAll(); err != nil {
return fmt.Errorf("While removing library Git clone: %s", err)
}
} else {
feedback.Warningf("Library Git clone folder %s not present", gitClonePath)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/libraries/repoclone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestBackupAndDeleteGitClone(t *testing.T) {
URL: "https://github.com/Foo/Bar.git",
}

assert.Error(t, BackupAndDeleteGitClone(&config, &repoMeta), "Error if library clone folder did not exist.")
assert.Nil(t, BackupAndDeleteGitClone(&config, &repoMeta), "Return nil if library clone folder did not exist.")

gitCloneSubfolder, err := repoMeta.AsFolder()
require.NoError(t, err)
Expand Down

0 comments on commit 893e86f

Please sign in to comment.