mirror of
https://github.com/go-gitea/gitea
synced 2024-12-25 01:54:26 +00:00
* Fix to close opened io resources as soon as not needed * Remove unneeded err checks
This commit is contained in:
parent
26457782c1
commit
68b7f9f3f7
@ -252,6 +252,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// download attachment
|
// download attachment
|
||||||
|
err = func() error {
|
||||||
resp, err := http.Get(asset.URL)
|
resp, err := http.Get(asset.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -269,10 +270,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
|||||||
}
|
}
|
||||||
defer fw.Close()
|
defer fw.Close()
|
||||||
|
|
||||||
if _, err := io.Copy(fw, resp.Body); err != nil {
|
_, err = io.Copy(fw, resp.Body)
|
||||||
|
return err
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rel.Attachments = append(rel.Attachments, &attach)
|
rel.Attachments = append(rel.Attachments, &attach)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,21 +471,24 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// download patch file
|
// download patch file
|
||||||
|
err := func() error {
|
||||||
resp, err := http.Get(pr.PatchURL)
|
resp, err := http.Get(pr.PatchURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
|
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
|
||||||
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
|
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
|
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
_, err = io.Copy(f, resp.Body)
|
_, err = io.Copy(f, resp.Body)
|
||||||
|
return err
|
||||||
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -496,8 +502,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer p.Close()
|
|
||||||
_, err = p.WriteString(pr.Head.SHA)
|
_, err = p.WriteString(pr.Head.SHA)
|
||||||
|
p.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -531,8 +537,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer b.Close()
|
|
||||||
_, err = b.WriteString(pr.Head.SHA)
|
_, err = b.WriteString(pr.Head.SHA)
|
||||||
|
b.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user