mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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")
|
||||
|
@@ -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()) {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user