Skip to content

Commit 893e86f

Browse files
committed
Don't error maintenance commands on missing library clone folder
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.
1 parent 01a027b commit 893e86f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

internal/libraries/repoclone.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/arduino/go-paths-helper"
3232
"github.com/arduino/libraries-repository-engine/internal/backup"
3333
"github.com/arduino/libraries-repository-engine/internal/configuration"
34+
"github.com/arduino/libraries-repository-engine/internal/feedback"
3435
"github.com/arduino/libraries-repository-engine/internal/libraries/db"
3536

3637
"fmt"
@@ -145,12 +146,21 @@ func BackupAndDeleteGitClone(config *configuration.Config, repoMeta *Repo) error
145146
return err
146147
}
147148
gitClonePath := paths.New(config.GitClonesFolder, gitCloneSubfolder)
148-
149-
if err := backup.Backup(gitClonePath); err != nil {
150-
return fmt.Errorf("While backing up library's Git clone: %w", err)
149+
// The library's clone folder may be removed by the sync process under expected circumstances.
150+
// So its absence does not necessarily imply a problem.
151+
gitClonePathExists, err := gitClonePath.ExistCheck()
152+
if err != nil {
153+
return err
151154
}
152-
if err := gitClonePath.RemoveAll(); err != nil {
153-
return fmt.Errorf("While removing library Git clone: %s", err)
155+
if gitClonePathExists {
156+
if err := backup.Backup(gitClonePath); err != nil {
157+
return fmt.Errorf("While backing up library's Git clone: %w", err)
158+
}
159+
if err := gitClonePath.RemoveAll(); err != nil {
160+
return fmt.Errorf("While removing library Git clone: %s", err)
161+
}
162+
} else {
163+
feedback.Warningf("Library Git clone folder %s not present", gitClonePath)
154164
}
155165

156166
return nil

internal/libraries/repoclone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestBackupAndDeleteGitClone(t *testing.T) {
6565
URL: "https://github.com/Foo/Bar.git",
6666
}
6767

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

7070
gitCloneSubfolder, err := repoMeta.AsFolder()
7171
require.NoError(t, err)

0 commit comments

Comments
 (0)