summaryrefslogtreecommitdiffstats
path: root/modules/migrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-02-18 08:36:49 +0800
committerGitHub <noreply@github.com>2021-02-18 01:36:49 +0100
commitec06eb112c92d4c49248e69648df6f13e10dff18 (patch)
tree8e91abd45b62851bf1091410bd28fd8058c738be /modules/migrations
parentae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb (diff)
downloadgitea-ec06eb112c92d4c49248e69648df6f13e10dff18.tar.gz
gitea-ec06eb112c92d4c49248e69648df6f13e10dff18.zip
Fix github download on migration (#14703)
* Fix github download on migration * Use Context for Client Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/migrations')
-rw-r--r--modules/migrations/github.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/modules/migrations/github.go b/modules/migrations/github.go
index 8d49f9308e..cb61086b2a 100644
--- a/modules/migrations/github.go
+++ b/modules/migrations/github.go
@@ -6,11 +6,9 @@
package migrations
import (
- "bytes"
"context"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/url"
"strings"
@@ -292,6 +290,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
}
for _, asset := range rel.Assets {
+ var assetID = *asset.ID // Don't optimize this, for closure we need a local variable
r.Assets = append(r.Assets, &base.ReleaseAsset{
ID: *asset.ID,
Name: *asset.Name,
@@ -302,7 +301,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
Updated: asset.UpdatedAt.Time,
DownloadFunc: func() (io.ReadCloser, error) {
g.sleep()
- asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, *asset.ID, http.DefaultClient)
+ asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, assetID, nil)
if err != nil {
return nil, err
}
@@ -311,7 +310,23 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
log.Error("g.client.RateLimits: %s", err)
}
if asset == nil {
- return ioutil.NopCloser(bytes.NewBufferString(redir)), nil
+ if redir != "" {
+ g.sleep()
+ req, err := http.NewRequestWithContext(g.ctx, "GET", redir, nil)
+ if err != nil {
+ return nil, err
+ }
+ resp, err := http.DefaultClient.Do(req)
+ err1 := g.RefreshRate()
+ if err1 != nil {
+ log.Error("g.client.RateLimits: %s", err1)
+ }
+ if err != nil {
+ return nil, err
+ }
+ return resp.Body, nil
+ }
+ return nil, fmt.Errorf("No release asset found for %d", assetID)
}
return asset, nil
},