fix(popcount): Accommodate upstream changes on nixos.org

Channel serving has moved to a new subdomain, and the redirect
semantics have changed. Instead of serving temporary redirects,
permanent redirects are now issued.

I've reported this upstream as a bug, but this workaround will fix it
in the meantime.
This commit is contained in:
Vincent Ambo 2020-05-01 12:47:31 +01:00 committed by Vincent Ambo
parent b4e0b55e56
commit 987a90510a

View file

@ -70,12 +70,16 @@ func channelMetadata(channel string) meta {
},
}
resp, err := c.Get(fmt.Sprintf("https://nixos.org/channels/%s", channel))
resp, err := c.Get(fmt.Sprintf("https://channels.nixos.org/%s", channel))
failOn(err, "failed to retrieve channel metadata")
loc, err := resp.Location()
failOn(err, "no redirect location given for channel")
if resp.StatusCode != 302 {
// TODO(tazjin): These redirects are currently served as 301s, but
// should (and used to) be 302s. Check if/when this is fixed and
// update accordingly.
if !(resp.StatusCode == 301 || resp.StatusCode == 302) {
log.Fatalf("Expected redirect for channel, but received '%s'\n", resp.Status)
}
@ -85,6 +89,9 @@ func channelMetadata(channel string) meta {
defer commitResp.Body.Close()
commit, err := ioutil.ReadAll(commitResp.Body)
failOn(err, "failed to read commit from response")
if commitResp.StatusCode != 200 {
log.Fatalf("non-success status code when fetching commit: %s", string(commit), commitResp.StatusCode)
}
return meta{
name: channel,