diff options
author | Eng Zer Jun <engzerjun@gmail.com> | 2021-09-22 13:38:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 13:38:34 +0800 |
commit | f2e7d5477f076789da5d0e95fe61a56ddb939f5a (patch) | |
tree | 922ca8769761c30e93f3b4deaf27858026b27ebf /routers/web | |
parent | aa631d8cd18251aa9b18ce72f75c8d8c7090e5e7 (diff) | |
download | gitea-f2e7d5477f076789da5d0e95fe61a56ddb939f5a.tar.gz gitea-f2e7d5477f076789da5d0e95fe61a56ddb939f5a.zip |
refactor: move from io/ioutil to io and os package (#17109)
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/editor.go | 4 | ||||
-rw-r--r-- | routers/web/repo/http.go | 3 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 4 | ||||
-rw-r--r-- | routers/web/repo/lfs.go | 3 | ||||
-rw-r--r-- | routers/web/repo/setting.go | 6 | ||||
-rw-r--r-- | routers/web/repo/settings_test.go | 4 | ||||
-rw-r--r-- | routers/web/repo/view.go | 9 | ||||
-rw-r--r-- | routers/web/repo/wiki.go | 4 | ||||
-rw-r--r-- | routers/web/repo/wiki_test.go | 4 | ||||
-rw-r--r-- | routers/web/user/auth.go | 3 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 6 |
11 files changed, 23 insertions, 27 deletions
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index a99c1c7c61..1d18bfe9a9 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -6,7 +6,7 @@ package repo import ( "fmt" - "io/ioutil" + "io" "net/http" "path" "strings" @@ -127,7 +127,7 @@ func editFile(ctx *context.Context, isNewFile bool) { return } - d, _ := ioutil.ReadAll(dataRc) + d, _ := io.ReadAll(dataRc) if err := dataRc.Close(); err != nil { log.Error("Error whilst closing blob data: %v", err) } diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 6078d764b6..fbd1e19a82 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -10,7 +10,6 @@ import ( "compress/gzip" gocontext "context" "fmt" - "io/ioutil" "net/http" "os" "os/exec" @@ -308,7 +307,7 @@ var ( func dummyInfoRefs(ctx *context.Context) { infoRefsOnce.Do(func() { - tmpDir, err := ioutil.TempDir(os.TempDir(), "gitea-info-refs-cache") + tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-info-refs-cache") if err != nil { log.Error("Failed to create temp dir for git-receive-pack cache: %v", err) return diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index bb3a0c8a9c..013286f2de 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -9,7 +9,7 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" + "io" "net/http" "path" "strconv" @@ -707,7 +707,7 @@ func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (str return "", false } defer r.Close() - bytes, err = ioutil.ReadAll(r) + bytes, err = io.ReadAll(r) if err != nil { return "", false } diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index e524a9209a..271c638553 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -9,7 +9,6 @@ import ( "fmt" gotemplate "html/template" "io" - "io/ioutil" "net/http" "path" "strconv" @@ -300,7 +299,7 @@ func LFSFileGet(ctx *context.Context) { buf := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc)) // Building code view blocks with line number on server side. - fileContent, _ := ioutil.ReadAll(buf) + fileContent, _ := io.ReadAll(buf) var output bytes.Buffer lines := strings.Split(string(fileContent), "\n") diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index ad7a330381..ed82c2eeb5 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -8,7 +8,7 @@ package repo import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -1126,9 +1126,9 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error { return errors.New(ctx.Tr("settings.uploaded_avatar_is_too_big")) } - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { - return fmt.Errorf("ioutil.ReadAll: %v", err) + return fmt.Errorf("io.ReadAll: %v", err) } st := typesniffer.DetectContentType(data) if !(st.IsImage() && !st.IsSvgImage()) { diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index f9986e44ed..a3ed271cce 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -5,8 +5,8 @@ package repo import ( - "io/ioutil" "net/http" + "os" "testing" "code.gitea.io/gitea/models" @@ -22,7 +22,7 @@ import ( ) func createSSHAuthorizedKeysTmpPath(t *testing.T) func() { - tmpDir, err := ioutil.TempDir("", "tmp-ssh") + tmpDir, err := os.MkdirTemp("", "tmp-ssh") if err != nil { assert.Fail(t, "Unable to create temporary directory: %v", err) return nil diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index c71562f271..addde15de1 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -11,7 +11,6 @@ import ( "fmt" gotemplate "html/template" "io" - "io/ioutil" "net/http" "net/url" "path" @@ -344,7 +343,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { }, rd, &result) if err != nil { log.Error("Render failed: %v then fallback", err) - bs, _ := ioutil.ReadAll(rd) + bs, _ := io.ReadAll(rd) ctx.Data["FileContent"] = strings.ReplaceAll( gotemplate.HTMLEscapeString(string(bs)), "\n", `<br>`, ) @@ -353,7 +352,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { } } else { ctx.Data["IsRenderedHTML"] = true - buf, err = ioutil.ReadAll(rd) + buf, err = io.ReadAll(rd) if err != nil { log.Error("ReadAll failed: %v", err) } @@ -528,13 +527,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st } ctx.Data["FileContent"] = result.String() } else if readmeExist { - buf, _ := ioutil.ReadAll(rd) + buf, _ := io.ReadAll(rd) ctx.Data["IsRenderedHTML"] = true ctx.Data["FileContent"] = strings.ReplaceAll( gotemplate.HTMLEscapeString(string(buf)), "\n", `<br>`, ) } else { - buf, _ := ioutil.ReadAll(rd) + buf, _ := io.ReadAll(rd) lineNums := linesBytesCount(buf) ctx.Data["NumLines"] = strconv.Itoa(lineNums) ctx.Data["NumLinesSet"] = true diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index f0b91aae99..a571c46fd7 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -8,7 +8,7 @@ package repo import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "path/filepath" @@ -110,7 +110,7 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte { return nil } defer reader.Close() - content, err := ioutil.ReadAll(reader) + content, err := io.ReadAll(reader) if err != nil { ctx.ServerError("ReadAll", err) return nil diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index df565487f1..14cb893d46 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -5,7 +5,7 @@ package repo import ( - "io/ioutil" + "io" "net/http" "testing" @@ -47,7 +47,7 @@ func wikiContent(t *testing.T, repo *models.Repository, wikiName string) string reader, err := entry.Blob().DataAsync() assert.NoError(t, err) defer reader.Close() - bytes, err := ioutil.ReadAll(reader) + bytes, err := io.ReadAll(reader) assert.NoError(t, err) return string(bytes) } diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go index b4c52675fd..9785ca68d5 100644 --- a/routers/web/user/auth.go +++ b/routers/web/user/auth.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -704,7 +703,7 @@ func updateAvatarIfNeed(url string, u *models.User) { } // ignore any error if err == nil && resp.StatusCode == http.StatusOK { - data, err := ioutil.ReadAll(io.LimitReader(resp.Body, setting.Avatar.MaxFileSize+1)) + data, err := io.ReadAll(io.LimitReader(resp.Body, setting.Avatar.MaxFileSize+1)) if err == nil && int64(len(data)) <= setting.Avatar.MaxFileSize { _ = u.UploadAvatar(data) } diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 15c08856b4..bd967af32b 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -8,7 +8,7 @@ package setting import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "os" "path/filepath" @@ -167,9 +167,9 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * return errors.New(ctx.Tr("settings.uploaded_avatar_is_too_big")) } - data, err := ioutil.ReadAll(fr) + data, err := io.ReadAll(fr) if err != nil { - return fmt.Errorf("ioutil.ReadAll: %v", err) + return fmt.Errorf("io.ReadAll: %v", err) } st := typesniffer.DetectContentType(data) |