-
Notifications
You must be signed in to change notification settings - Fork 65
fix: fallbacks on current archive if old release not moved yet #313
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
+155
−56
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c58bd5
fix: fallbacks on current archive if old release not moved yet
upils fda7d25
refactor: implement cleaner fallback
upils 3b4878e
style: refine to a more idiomatic error handling
upils 973791a
tests: cover no release found case and refine docs
upils File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,47 @@ func (a *ubuntuArchive) Info(pkg string) (*PackageInfo, error) { | |
| return info, nil | ||
| } | ||
|
|
||
| // setupIndexes fetches the release and package indexes of every suite and | ||
| // component, registering the resulting indexes on the archive. | ||
| func (a *ubuntuArchive) setupIndexes() error { | ||
| for _, suite := range a.options.Suites { | ||
| var release control.Section | ||
| for _, component := range a.options.Components { | ||
| index := &ubuntuIndex{ | ||
| label: a.options.Label, | ||
| version: a.options.Version, | ||
| arch: a.options.Arch, | ||
| suite: suite, | ||
| component: component, | ||
| release: release, | ||
| archive: a, | ||
| } | ||
| if release == nil { | ||
| err := index.fetchRelease() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| release = index.release | ||
| if !index.supportsArch(a.options.Arch) { | ||
| // Release does not support the specified architecture, do | ||
| // not add any of its indexes. | ||
| break | ||
| } | ||
| err = index.checkComponents(a.options.Components) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| err := index.fetchIndex() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| a.indexes = append(a.indexes, index) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| const ubuntuURL = "http://archive.ubuntu.com/ubuntu/" | ||
| const ubuntuOldReleasesURL = "http://old-releases.ubuntu.com/ubuntu/" | ||
| const ubuntuPortsURL = "http://ports.ubuntu.com/ubuntu-ports/" | ||
|
|
@@ -189,28 +230,37 @@ var proArchiveInfo = map[string]struct { | |
| }, | ||
| } | ||
|
|
||
| func archiveURL(pro, arch string, oldRelease bool) (string, *credentials, error) { | ||
| // candidateArchiveURLs returns the candidate base URLs of the archive, in order of | ||
| // preference, and the credentials used to access them, if any. | ||
| // | ||
| // Ubuntu releases are moved from the regular archive to | ||
| // old-releases.ubuntu.com after their end of life, but not immediately: | ||
| // until the move happens the release is only available from the regular | ||
| // archive. For such releases both archives are returned, so that the | ||
| // caller can fall back to the regular one when the release is not found | ||
| // in the old-releases one. | ||
| func candidateArchiveURLs(pro, arch string, oldRelease bool) ([]string, *credentials, error) { | ||
| if pro != "" { | ||
| archiveInfo, ok := proArchiveInfo[pro] | ||
| if !ok { | ||
| return "", nil, fmt.Errorf("invalid pro value: %q", pro) | ||
| return nil, nil, fmt.Errorf("invalid pro value: %q", pro) | ||
| } | ||
| url := archiveInfo.BaseURL | ||
| creds, err := findCredentials(url) | ||
| if err != nil { | ||
| return "", nil, err | ||
| return nil, nil, err | ||
| } | ||
| return url, creds, nil | ||
| return []string{url}, creds, nil | ||
| } | ||
|
|
||
| if oldRelease { | ||
| return ubuntuOldReleasesURL, nil, nil | ||
| current := ubuntuURL | ||
| if arch != "amd64" && arch != "i386" { | ||
| current = ubuntuPortsURL | ||
| } | ||
|
|
||
| if arch == "amd64" || arch == "i386" { | ||
| return ubuntuURL, nil, nil | ||
| if oldRelease { | ||
| return []string{ubuntuOldReleasesURL, current}, nil, nil | ||
| } | ||
| return ubuntuPortsURL, nil, nil | ||
| return []string{current}, nil, nil | ||
| } | ||
|
|
||
| func openUbuntu(options *Options) (Archive, error) { | ||
|
|
@@ -224,58 +274,31 @@ func openUbuntu(options *Options) (Archive, error) { | |
| return nil, fmt.Errorf("archive options missing version") | ||
| } | ||
|
|
||
| baseURL, creds, err := archiveURL(options.Pro, options.Arch, options.OldRelease) | ||
| candidates, creds, err := candidateArchiveURLs(options.Pro, options.Arch, options.OldRelease) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| archive := &ubuntuArchive{ | ||
| options: *options, | ||
| cache: &cache.Cache{ | ||
| Dir: options.CacheDir, | ||
| }, | ||
| pubKeys: options.PubKeys, | ||
| baseURL: baseURL, | ||
| creds: creds, | ||
| } | ||
|
|
||
| for _, suite := range options.Suites { | ||
| var release control.Section | ||
| for _, component := range options.Components { | ||
| index := &ubuntuIndex{ | ||
| label: options.Label, | ||
| version: options.Version, | ||
| arch: options.Arch, | ||
| suite: suite, | ||
| component: component, | ||
| release: release, | ||
| archive: archive, | ||
| } | ||
| if release == nil { | ||
| err := index.fetchRelease() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| release = index.release | ||
| if !index.supportsArch(options.Arch) { | ||
| // Release does not support the specified architecture, do | ||
| // not add any of its indexes. | ||
| break | ||
| } | ||
| err = index.checkComponents(options.Components) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| err := index.fetchIndex() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| archive.indexes = append(archive.indexes, index) | ||
| // Try the candidate archives in order until the release is found. | ||
| for _, baseURL := range candidates { | ||
| archive := &ubuntuArchive{ | ||
| options: *options, | ||
| cache: &cache.Cache{Dir: options.CacheDir}, | ||
| pubKeys: options.PubKeys, | ||
| baseURL: baseURL, | ||
| creds: creds, | ||
| } | ||
| err := archive.setupIndexes() | ||
| if err == errNotFound { | ||
| // Release not in this archive, try the next candidate. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is not required, as the code is literally spelling it out: The |
||
| continue | ||
| } | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return archive, nil | ||
| } | ||
|
|
||
| return archive, nil | ||
| return nil, errNotFound | ||
| } | ||
|
|
||
| func (index *ubuntuIndex) fetchRelease() error { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer, thanks.