Skip to content

Commit d050161

Browse files
committed
Don't preserve old repository on URL change
The library maintainers may request a change to the repository URL in the library registration data. This operation is performed by the backend maintainer via the command: libraries-repository-engine modify --repo-url Previously, this command did three things: - Update the DB entry for the library - Move the release archives to the new location (the storage structure is based on the repository URL for some reason) - Move the cached library repository clone to the new location Problem ------- The last of these is problematic because the remote of that repository is still configured for the original URL, meaning the fetch done during the `sync` command execution were still done against the old URL. This bug is not noticeable under either of the following scenarios: The repository was renamed or transferred ========================================= This produces a redirect from the old URL to the new one, so the fetch is done from the intended repo despite the outdated remote configuration. The original repository was deleted =================================== If a fetch fails, the engine deletes the repository and clones from the URL in the DB. The newly cloned repo will have the correct remote configuration. The bug is noticeable under the following scenario: The original repository still exists ==================================== The sync process continues to fetch from the old URL. Solution -------- Change the `modify --repo-url` command behavior to delete the cached library repository clone. The repository will be cloned from the updated URL on the next run of the `sync` command.
1 parent 087e041 commit d050161

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

internal/command/modify/modify.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,18 @@ func modifyRepositoryURL(newRepositoryURL string) error {
163163

164164
fmt.Printf("Changing URL of library %s from %s to %s\n", libraryName, oldRepositoryURL, newRepositoryURL)
165165

166-
// Move the library Git clone to the new path.
167-
gitClonePath := func(url string) (*paths.Path, error) {
168-
libraryRegistration := libraries.Repo{URL: url}
169-
gitCloneSubfolder, err := libraryRegistration.AsFolder()
170-
if err != nil {
171-
return nil, err
172-
}
173-
174-
return paths.New(config.GitClonesFolder, gitCloneSubfolder), nil
175-
}
176-
oldGitClonePath, err := gitClonePath(oldRepositoryURL)
166+
// Remove the library Git clone folder. It will be cloned from the new URL on the next sync.
167+
libraryRegistration := libraries.Repo{URL: libraryData.Repository}
168+
gitCloneSubfolder, err := libraryRegistration.AsFolder()
177169
if err != nil {
178170
return err
179171
}
180-
newGitClonePath, err := gitClonePath(newRepositoryURL)
181-
if err != nil {
182-
return err
183-
}
184-
if err := newGitClonePath.Parent().MkdirAll(); err != nil {
185-
return fmt.Errorf("While creating new library Git clone path: %w", err)
186-
}
187-
if err := backup.Backup(oldGitClonePath); err != nil {
172+
gitClonePath := paths.New(config.GitClonesFolder, gitCloneSubfolder)
173+
if err := backup.Backup(gitClonePath); err != nil {
188174
return fmt.Errorf("While backing up library's Git clone: %w", err)
189175
}
190-
if err := oldGitClonePath.Rename(newGitClonePath); err != nil {
191-
return fmt.Errorf("While moving library's Git clone: %w", err)
176+
if err := gitClonePath.RemoveAll(); err != nil {
177+
return fmt.Errorf("While removing library's Git clone: %w", err)
192178
}
193179

194180
// Update the library repository URL in the database.

tests/test_modify.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ def test_repo_url(
227227
new_library_release_archives_folder = pathlib.Path(configuration.data["LibrariesFolder"]).joinpath(
228228
new_host, new_owner
229229
)
230-
new_git_clone_path = pathlib.Path(configuration.data["GitClonesFolder"]).joinpath(
231-
new_host, new_owner, new_repo_name
232-
)
233230
# The "canary" library is not modified and so all its content should remain unchanged after running the command
234231
canary_name = "ArduinoIoTCloudBearSSL"
235232
sanitized_canary_name = "ArduinoIoTCloudBearSSL"
@@ -281,7 +278,6 @@ def get_release_archive_url(name, version):
281278
raise
282279

283280
assert old_git_clone_path.exists()
284-
assert not new_git_clone_path.exists()
285281
assert canary_git_clone_path.exists()
286282
assert get_library_repo_url(name=name) != new_repo_url
287283
assert get_library_repo_url(name=canary_name) == canary_repo_url
@@ -314,7 +310,6 @@ def get_release_archive_url(name, version):
314310

315311
# Verify the effect of the command was as expected
316312
assert not old_git_clone_path.exists()
317-
assert new_git_clone_path.exists()
318313
assert canary_release_archive_path.exists()
319314
assert canary_git_clone_path.exists()
320315
assert get_library_repo_url(name=name) == new_repo_url

0 commit comments

Comments
 (0)