aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2021-09-22 13:38:34 +0800
committerGitHub <noreply@github.com>2021-09-22 13:38:34 +0800
commitf2e7d5477f076789da5d0e95fe61a56ddb939f5a (patch)
tree922ca8769761c30e93f3b4deaf27858026b27ebf /modules
parentaa631d8cd18251aa9b18ce72f75c8d8c7090e5e7 (diff)
downloadgitea-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 'modules')
-rw-r--r--modules/avatar/avatar_test.go8
-rw-r--r--modules/charset/charset.go3
-rw-r--r--modules/context/repo.go4
-rw-r--r--modules/doctor/paths.go3
-rw-r--r--modules/git/blame_test.go4
-rw-r--r--modules/git/blob.go3
-rw-r--r--modules/git/blob_nogogit.go5
-rw-r--r--modules/git/blob_test.go6
-rw-r--r--modules/git/hook.go9
-rw-r--r--modules/git/notes_gogit.go4
-rw-r--r--modules/git/notes_nogogit.go4
-rw-r--r--modules/git/repo_blob_test.go4
-rw-r--r--modules/git/repo_commit.go5
-rw-r--r--modules/git/repo_commit_nogogit.go3
-rw-r--r--modules/git/repo_compare_test.go4
-rw-r--r--modules/git/repo_index.go3
-rw-r--r--modules/git/repo_language_stats_gogit.go6
-rw-r--r--modules/git/repo_language_stats_nogogit.go4
-rw-r--r--modules/git/repo_tree_nogogit.go3
-rw-r--r--modules/graceful/server.go5
-rw-r--r--modules/httplib/httplib.go9
-rw-r--r--modules/indexer/code/bleve.go3
-rw-r--r--modules/indexer/code/bleve_test.go4
-rw-r--r--modules/indexer/code/elastic_search.go3
-rw-r--r--modules/indexer/issues/bleve_test.go4
-rw-r--r--modules/indexer/issues/indexer_test.go4
-rw-r--r--modules/lfs/http_client_test.go9
-rw-r--r--modules/lfs/transferadapter_test.go5
-rw-r--r--modules/log/conn_test.go4
-rw-r--r--modules/log/file_test.go34
-rw-r--r--modules/log/stack.go4
-rw-r--r--modules/markup/csv/csv.go3
-rw-r--r--modules/markup/external/external.go3
-rw-r--r--modules/markup/html.go3
-rw-r--r--modules/markup/markdown/markdown.go3
-rw-r--r--modules/migrations/restore.go19
-rw-r--r--modules/options/dynamic.go6
-rw-r--r--modules/options/static.go9
-rw-r--r--modules/pprof/pprof.go6
-rw-r--r--modules/private/key.go4
-rw-r--r--modules/private/mail.go4
-rw-r--r--modules/private/restore_repo.go4
-rw-r--r--modules/public/static.go3
-rw-r--r--modules/queue/queue_disk_channel_test.go4
-rw-r--r--modules/queue/queue_disk_test.go4
-rw-r--r--modules/recaptcha/recaptcha.go4
-rw-r--r--modules/repository/generate.go9
-rw-r--r--modules/repository/hooks.go9
-rw-r--r--modules/repository/init.go9
-rw-r--r--modules/setting/setting.go5
-rw-r--r--modules/storage/local.go3
-rw-r--r--modules/svg/discover_nobindata.go4
-rw-r--r--modules/templates/dynamic.go9
-rw-r--r--modules/templates/static.go8
54 files changed, 141 insertions, 167 deletions
diff --git a/modules/avatar/avatar_test.go b/modules/avatar/avatar_test.go
index f48266c858..b958a9e236 100644
--- a/modules/avatar/avatar_test.go
+++ b/modules/avatar/avatar_test.go
@@ -5,7 +5,7 @@
package avatar
import (
- "io/ioutil"
+ "os"
"testing"
"code.gitea.io/gitea/modules/setting"
@@ -30,7 +30,7 @@ func Test_PrepareWithPNG(t *testing.T) {
setting.Avatar.MaxWidth = 4096
setting.Avatar.MaxHeight = 4096
- data, err := ioutil.ReadFile("testdata/avatar.png")
+ data, err := os.ReadFile("testdata/avatar.png")
assert.NoError(t, err)
imgPtr, err := Prepare(data)
@@ -44,7 +44,7 @@ func Test_PrepareWithJPEG(t *testing.T) {
setting.Avatar.MaxWidth = 4096
setting.Avatar.MaxHeight = 4096
- data, err := ioutil.ReadFile("testdata/avatar.jpeg")
+ data, err := os.ReadFile("testdata/avatar.jpeg")
assert.NoError(t, err)
imgPtr, err := Prepare(data)
@@ -65,7 +65,7 @@ func Test_PrepareWithInvalidImageSize(t *testing.T) {
setting.Avatar.MaxWidth = 5
setting.Avatar.MaxHeight = 5
- data, err := ioutil.ReadFile("testdata/avatar.png")
+ data, err := os.ReadFile("testdata/avatar.png")
assert.NoError(t, err)
_, err = Prepare(data)
diff --git a/modules/charset/charset.go b/modules/charset/charset.go
index 3000864c2e..47906e2638 100644
--- a/modules/charset/charset.go
+++ b/modules/charset/charset.go
@@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"io"
- "io/ioutil"
"strings"
"unicode/utf8"
@@ -78,7 +77,7 @@ func ToUTF8WithErr(content []byte) (string, error) {
// ToUTF8WithFallback detects the encoding of content and coverts to UTF-8 if possible
func ToUTF8WithFallback(content []byte) []byte {
- bs, _ := ioutil.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content)))
+ bs, _ := io.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content)))
return bs
}
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 89ff890cc3..eceefd9e59 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -8,7 +8,7 @@ package context
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"net/url"
"path"
"strings"
@@ -915,7 +915,7 @@ func (ctx *Context) IssueTemplatesFromDefaultBranch() []api.IssueTemplate {
_ = r.Close()
}
}()
- data, err := ioutil.ReadAll(r)
+ data, err := io.ReadAll(r)
if err != nil {
log.Debug("ReadAll: %v", err)
continue
diff --git a/modules/doctor/paths.go b/modules/doctor/paths.go
index 53409b5fa4..88172d3150 100644
--- a/modules/doctor/paths.go
+++ b/modules/doctor/paths.go
@@ -6,7 +6,6 @@ package doctor
import (
"fmt"
- "io/ioutil"
"os"
"code.gitea.io/gitea/modules/log"
@@ -102,7 +101,7 @@ func isWritableDir(path string) error {
// There's no platform-independent way of checking if a directory is writable
// https://stackoverflow.com/questions/20026320/how-to-tell-if-folder-exists-and-is-writable
- tmpFile, err := ioutil.TempFile(path, "doctors-order")
+ tmpFile, err := os.CreateTemp(path, "doctors-order")
if err != nil {
return err
}
diff --git a/modules/git/blame_test.go b/modules/git/blame_test.go
index 734d63ee14..4bee8cd27a 100644
--- a/modules/git/blame_test.go
+++ b/modules/git/blame_test.go
@@ -6,7 +6,7 @@ package git
import (
"context"
- "io/ioutil"
+ "os"
"testing"
"github.com/stretchr/testify/assert"
@@ -84,7 +84,7 @@ e2aa991e10ffd924a828ec149951f2f20eecead2 7 7
`
func TestReadingBlameOutput(t *testing.T) {
- tempFile, err := ioutil.TempFile("", ".txt")
+ tempFile, err := os.CreateTemp("", ".txt")
if err != nil {
panic(err)
}
diff --git a/modules/git/blob.go b/modules/git/blob.go
index 5831bc3735..c7919f3c41 100644
--- a/modules/git/blob.go
+++ b/modules/git/blob.go
@@ -9,7 +9,6 @@ import (
"bytes"
"encoding/base64"
"io"
- "io/ioutil"
"code.gitea.io/gitea/modules/typesniffer"
)
@@ -83,7 +82,7 @@ func (b *Blob) GetBlobContentBase64() (string, error) {
}
}()
- out, err := ioutil.ReadAll(pr)
+ out, err := io.ReadAll(pr)
if err != nil {
return "", err
}
diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go
index 3391bc3931..65a73ebc52 100644
--- a/modules/git/blob_nogogit.go
+++ b/modules/git/blob_nogogit.go
@@ -11,7 +11,6 @@ import (
"bufio"
"bytes"
"io"
- "io/ioutil"
"math"
"code.gitea.io/gitea/modules/log"
@@ -46,13 +45,13 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
b.size = size
if size < 4096 {
- bs, err := ioutil.ReadAll(io.LimitReader(rd, size))
+ bs, err := io.ReadAll(io.LimitReader(rd, size))
defer cancel()
if err != nil {
return nil, err
}
_, err = rd.Discard(1)
- return ioutil.NopCloser(bytes.NewReader(bs)), err
+ return io.NopCloser(bytes.NewReader(bs)), err
}
return &blobReader{
diff --git a/modules/git/blob_test.go b/modules/git/blob_test.go
index 2ceda6c4ef..34d8054d1e 100644
--- a/modules/git/blob_test.go
+++ b/modules/git/blob_test.go
@@ -6,7 +6,7 @@
package git
import (
- "io/ioutil"
+ "io"
"path/filepath"
"testing"
@@ -30,7 +30,7 @@ func TestBlob_Data(t *testing.T) {
assert.NoError(t, err)
require.NotNil(t, r)
- data, err := ioutil.ReadAll(r)
+ data, err := io.ReadAll(r)
assert.NoError(t, r.Close())
assert.NoError(t, err)
@@ -55,7 +55,7 @@ func Benchmark_Blob_Data(b *testing.B) {
if err != nil {
b.Fatal(err)
}
- ioutil.ReadAll(r)
+ io.ReadAll(r)
_ = r.Close()
}
}
diff --git a/modules/git/hook.go b/modules/git/hook.go
index 7007d23be2..ecd2db3cc3 100644
--- a/modules/git/hook.go
+++ b/modules/git/hook.go
@@ -7,7 +7,6 @@ package git
import (
"errors"
- "io/ioutil"
"os"
"path"
"path/filepath"
@@ -59,14 +58,14 @@ func GetHook(repoPath, name string) (*Hook, error) {
}
samplePath := filepath.Join(repoPath, "hooks", name+".sample")
if isFile(h.path) {
- data, err := ioutil.ReadFile(h.path)
+ data, err := os.ReadFile(h.path)
if err != nil {
return nil, err
}
h.IsActive = true
h.Content = string(data)
} else if isFile(samplePath) {
- data, err := ioutil.ReadFile(samplePath)
+ data, err := os.ReadFile(samplePath)
if err != nil {
return nil, err
}
@@ -97,7 +96,7 @@ func (h *Hook) Update() error {
return err
}
- err := ioutil.WriteFile(h.path, []byte(strings.ReplaceAll(h.Content, "\r", "")), os.ModePerm)
+ err := os.WriteFile(h.path, []byte(strings.ReplaceAll(h.Content, "\r", "")), os.ModePerm)
if err != nil {
return err
}
@@ -143,5 +142,5 @@ func SetUpdateHook(repoPath, content string) (err error) {
if err != nil {
return err
}
- return ioutil.WriteFile(hookPath, []byte(content), 0777)
+ return os.WriteFile(hookPath, []byte(content), 0777)
}
diff --git a/modules/git/notes_gogit.go b/modules/git/notes_gogit.go
index 84f66d86bf..28dbbc0ee5 100644
--- a/modules/git/notes_gogit.go
+++ b/modules/git/notes_gogit.go
@@ -9,7 +9,7 @@ package git
import (
"context"
- "io/ioutil"
+ "io"
"code.gitea.io/gitea/modules/log"
@@ -58,7 +58,7 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
}
defer dataRc.Close()
- d, err := ioutil.ReadAll(dataRc)
+ d, err := io.ReadAll(dataRc)
if err != nil {
log.Error("Unable to read blob with ID %q. Error: %v", blob.ID, err)
return err
diff --git a/modules/git/notes_nogogit.go b/modules/git/notes_nogogit.go
index 9a54b48106..5afe8d4614 100644
--- a/modules/git/notes_nogogit.go
+++ b/modules/git/notes_nogogit.go
@@ -9,7 +9,7 @@ package git
import (
"context"
- "io/ioutil"
+ "io"
"strings"
"code.gitea.io/gitea/modules/log"
@@ -60,7 +60,7 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
_ = dataRc.Close()
}
}()
- d, err := ioutil.ReadAll(dataRc)
+ d, err := io.ReadAll(dataRc)
if err != nil {
log.Error("Unable to read blob with ID %q. Error: %v", blob.ID, err)
return err
diff --git a/modules/git/repo_blob_test.go b/modules/git/repo_blob_test.go
index ccf418b305..132a3fa50c 100644
--- a/modules/git/repo_blob_test.go
+++ b/modules/git/repo_blob_test.go
@@ -6,7 +6,7 @@ package git
import (
"fmt"
- "io/ioutil"
+ "io"
"path/filepath"
"testing"
@@ -34,7 +34,7 @@ func TestRepository_GetBlob_Found(t *testing.T) {
dataReader, err := blob.DataAsync()
assert.NoError(t, err)
- data, err := ioutil.ReadAll(dataReader)
+ data, err := io.ReadAll(dataReader)
assert.NoError(t, dataReader.Close())
assert.NoError(t, err)
assert.Equal(t, testCase.Data, data)
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index e456f04e87..25060f56da 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -8,7 +8,6 @@ package git
import (
"bytes"
"io"
- "io/ioutil"
"strconv"
"strings"
@@ -222,7 +221,7 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (
}()
if skip > 0 {
- _, err := io.CopyN(ioutil.Discard, stdoutReader, int64(skip*41))
+ _, err := io.CopyN(io.Discard, stdoutReader, int64(skip*41))
if err != nil {
if err == io.EOF {
return []*Commit{}, nil
@@ -232,7 +231,7 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (
}
}
- stdout, err := ioutil.ReadAll(stdoutReader)
+ stdout, err := io.ReadAll(stdoutReader)
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go
index b7e49a6501..8bfc953759 100644
--- a/modules/git/repo_commit_nogogit.go
+++ b/modules/git/repo_commit_nogogit.go
@@ -11,7 +11,6 @@ import (
"bufio"
"errors"
"io"
- "io/ioutil"
"strings"
"code.gitea.io/gitea/modules/log"
@@ -77,7 +76,7 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
case "tag":
// then we need to parse the tag
// and load the commit
- data, err := ioutil.ReadAll(io.LimitReader(rd, size))
+ data, err := io.ReadAll(io.LimitReader(rd, size))
if err != nil {
return nil, err
}
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go
index f0e20838f4..3a6cda955c 100644
--- a/modules/git/repo_compare_test.go
+++ b/modules/git/repo_compare_test.go
@@ -6,7 +6,7 @@ package git
import (
"bytes"
- "io/ioutil"
+ "io"
"path/filepath"
"testing"
@@ -25,7 +25,7 @@ func TestGetFormatPatch(t *testing.T) {
rd := &bytes.Buffer{}
err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
assert.NoError(t, err)
- patchb, err := ioutil.ReadAll(rd)
+ patchb, err := io.ReadAll(rd)
assert.NoError(t, err)
patch := string(patchb)
assert.Regexp(t, "^From 8d92fc95", patch)
diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go
index b301ff2437..27cb7fbebe 100644
--- a/modules/git/repo_index.go
+++ b/modules/git/repo_index.go
@@ -7,7 +7,6 @@ package git
import (
"bytes"
"context"
- "io/ioutil"
"os"
"strings"
@@ -47,7 +46,7 @@ func (repo *Repository) readTreeToIndex(id SHA1, indexFilename ...string) error
// ReadTreeToTemporaryIndex reads a treeish to a temporary index file
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename string, cancel context.CancelFunc, err error) {
- tmpIndex, err := ioutil.TempFile("", "index")
+ tmpIndex, err := os.CreateTemp("", "index")
if err != nil {
return
}
diff --git a/modules/git/repo_language_stats_gogit.go b/modules/git/repo_language_stats_gogit.go
index 1f2738a5a8..d37827c3de 100644
--- a/modules/git/repo_language_stats_gogit.go
+++ b/modules/git/repo_language_stats_gogit.go
@@ -11,7 +11,7 @@ import (
"bytes"
"context"
"io"
- "io/ioutil"
+ "os"
"code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/log"
@@ -51,7 +51,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
indexFilename, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)
if err == nil {
defer deleteTemporaryFile()
- tmpWorkTree, err := ioutil.TempDir("", "empty-work-dir")
+ tmpWorkTree, err := os.MkdirTemp("", "empty-work-dir")
if err == nil {
defer func() {
_ = util.RemoveAll(tmpWorkTree)
@@ -174,7 +174,7 @@ func readFile(f *object.File, limit int64) ([]byte, error) {
defer r.Close()
if limit <= 0 {
- return ioutil.ReadAll(r)
+ return io.ReadAll(r)
}
size := f.Size
diff --git a/modules/git/repo_language_stats_nogogit.go b/modules/git/repo_language_stats_nogogit.go
index 8e9a3d6bcd..06269a466c 100644
--- a/modules/git/repo_language_stats_nogogit.go
+++ b/modules/git/repo_language_stats_nogogit.go
@@ -12,8 +12,8 @@ import (
"bytes"
"context"
"io"
- "io/ioutil"
"math"
+ "os"
"code.gitea.io/gitea/modules/analyze"
"code.gitea.io/gitea/modules/log"
@@ -71,7 +71,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
indexFilename, deleteTemporaryFile, err := repo.ReadTreeToTemporaryIndex(commitID)
if err == nil {
defer deleteTemporaryFile()
- tmpWorkTree, err := ioutil.TempDir("", "empty-work-dir")
+ tmpWorkTree, err := os.MkdirTemp("", "empty-work-dir")
if err == nil {
defer func() {
_ = util.RemoveAll(tmpWorkTree)
diff --git a/modules/git/repo_tree_nogogit.go b/modules/git/repo_tree_nogogit.go
index 9d4268b13a..b27abb6e02 100644
--- a/modules/git/repo_tree_nogogit.go
+++ b/modules/git/repo_tree_nogogit.go
@@ -9,7 +9,6 @@ package git
import (
"io"
- "io/ioutil"
)
func (repo *Repository) getTree(id SHA1) (*Tree, error) {
@@ -27,7 +26,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
switch typ {
case "tag":
resolvedID := id
- data, err := ioutil.ReadAll(io.LimitReader(rd, size))
+ data, err := io.ReadAll(io.LimitReader(rd, size))
if err != nil {
return nil, err
}
diff --git a/modules/graceful/server.go b/modules/graceful/server.go
index 6b7d4a1a97..23eb821c8c 100644
--- a/modules/graceful/server.go
+++ b/modules/graceful/server.go
@@ -7,7 +7,6 @@ package graceful
import (
"crypto/tls"
- "io/ioutil"
"net"
"os"
"strings"
@@ -111,13 +110,13 @@ func (srv *Server) ListenAndServeTLS(certFile, keyFile string, serve ServeFuncti
config.Certificates = make([]tls.Certificate, 1)
- certPEMBlock, err := ioutil.ReadFile(certFile)
+ certPEMBlock, err := os.ReadFile(certFile)
if err != nil {
log.Error("Failed to load https cert file %s for %s:%s: %v", certFile, srv.network, srv.address, err)
return err
}
- keyPEMBlock, err := ioutil.ReadFile(keyFile)
+ keyPEMBlock, err := os.ReadFile(keyFile)
if err != nil {
log.Error("Failed to load https key file %s for %s:%s: %v", keyFile, srv.network, srv.address, err)
return err
diff --git a/modules/httplib/httplib.go b/modules/httplib/httplib.go
index aecdd4346c..ad3b7462e9 100644
--- a/modules/httplib/httplib.go
+++ b/modules/httplib/httplib.go
@@ -11,7 +11,6 @@ import (
"crypto/tls"
"encoding/xml"
"io"
- "io/ioutil"
"log"
"mime/multipart"
"net"
@@ -243,11 +242,11 @@ func (r *Request) Body(data interface{}) *Request {
switch t := data.(type) {
case string:
bf := bytes.NewBufferString(t)
- r.req.Body = ioutil.NopCloser(bf)
+ r.req.Body = io.NopCloser(bf)
r.req.ContentLength = int64(len(t))
case []byte:
bf := bytes.NewBuffer(t)
- r.req.Body = ioutil.NopCloser(bf)
+ r.req.Body = io.NopCloser(bf)
r.req.ContentLength = int64(len(t))
}
return r
@@ -307,7 +306,7 @@ func (r *Request) getResponse() (*http.Response, error) {
_ = pw.Close()
}()
r.Header("Content-Type", bodyWriter.FormDataContentType())
- r.req.Body = ioutil.NopCloser(pr)
+ r.req.Body = io.NopCloser(pr)
} else if len(paramBody) > 0 {
r.Header("Content-Type", "application/x-www-form-urlencoded")
r.Body(paramBody)
@@ -407,7 +406,7 @@ func (r *Request) Bytes() ([]byte, error) {
return nil, nil
}
defer resp.Body.Close()
- data, err := ioutil.ReadAll(resp.Body)
+ data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go
index fc5c602dbe..8e5df34e60 100644
--- a/modules/indexer/code/bleve.go
+++ b/modules/indexer/code/bleve.go
@@ -8,7 +8,6 @@ import (
"bufio"
"fmt"
"io"
- "io/ioutil"
"os"
"strconv"
"strings"
@@ -210,7 +209,7 @@ func (b *BleveIndexer) addUpdate(batchWriter git.WriteCloserError, batchReader *
return err
}
- fileContents, err := ioutil.ReadAll(io.LimitReader(batchReader, size))
+ fileContents, err := io.ReadAll(io.LimitReader(batchReader, size))
if err != nil {
return err
} else if !typesniffer.DetectContentType(fileContents).IsText() {
diff --git a/modules/indexer/code/bleve_test.go b/modules/indexer/code/bleve_test.go
index 1199dc98a0..3d97e312f9 100644
--- a/modules/indexer/code/bleve_test.go
+++ b/modules/indexer/code/bleve_test.go
@@ -5,7 +5,7 @@
package code
import (
- "io/ioutil"
+ "os"
"testing"
"code.gitea.io/gitea/models/db"
@@ -17,7 +17,7 @@ import (
func TestBleveIndexAndSearch(t *testing.T) {
db.PrepareTestEnv(t)
- dir, err := ioutil.TempDir("", "bleve.index")
+ dir, err := os.MkdirTemp("", "bleve.index")
assert.NoError(t, err)
if err != nil {
assert.Fail(t, "Unable to create temporary directory")
diff --git a/modules/indexer/code/elastic_search.go b/modules/indexer/code/elastic_search.go
index a7a243e24e..49633c3191 100644
--- a/modules/indexer/code/elastic_search.go
+++ b/modules/indexer/code/elastic_search.go
@@ -9,7 +9,6 @@ import (
"context"
"fmt"
"io"
- "io/ioutil"
"strconv"
"strings"
"time"
@@ -207,7 +206,7 @@ func (b *ElasticSearchIndexer) addUpdate(batchWriter git.WriteCloserError, batch
return nil, err
}
- fileContents, err := ioutil.ReadAll(io.LimitReader(batchReader, size))
+ fileContents, err := io.ReadAll(io.LimitReader(batchReader, size))
if err != nil {
return nil, err
} else if !typesniffer.DetectContentType(fileContents).IsText() {
diff --git a/modules/indexer/issues/bleve_test.go b/modules/indexer/issues/bleve_test.go
index 2a8ed15d82..70a9582e1d 100644
--- a/modules/indexer/issues/bleve_test.go
+++ b/modules/indexer/issues/bleve_test.go
@@ -5,7 +5,7 @@
package issues
import (
- "io/ioutil"
+ "os"
"testing"
"code.gitea.io/gitea/modules/util"
@@ -13,7 +13,7 @@ import (
)
func TestBleveIndexAndSearch(t *testing.T) {
- dir, err := ioutil.TempDir("", "bleve.index")
+ dir, err := os.MkdirTemp("", "bleve.index")
assert.NoError(t, err)
if err != nil {
assert.Fail(t, "Unable to create temporary directory")
diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go
index 1431115b8e..561f357f4d 100644
--- a/modules/indexer/issues/indexer_test.go
+++ b/modules/indexer/issues/indexer_test.go
@@ -5,7 +5,7 @@
package issues
import (
- "io/ioutil"
+ "os"
"path"
"path/filepath"
"testing"
@@ -28,7 +28,7 @@ func TestBleveSearchIssues(t *testing.T) {
assert.NoError(t, db.PrepareTestDatabase())
setting.Cfg = ini.Empty()
- tmpIndexerDir, err := ioutil.TempDir("", "issues-indexer")
+ tmpIndexerDir, err := os.MkdirTemp("", "issues-indexer")
if err != nil {
assert.Fail(t, "Unable to create temporary directory: %v", err)
return
diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go
index 589773e45b..5b514a1230 100644
--- a/modules/lfs/http_client_test.go
+++ b/modules/lfs/http_client_test.go
@@ -8,7 +8,6 @@ import (
"bytes"
"context"
"io"
- "io/ioutil"
"net/http"
"strings"
"testing"
@@ -32,7 +31,7 @@ func (a *DummyTransferAdapter) Name() string {
}
func (a *DummyTransferAdapter) Download(ctx context.Context, l *Link) (io.ReadCloser, error) {
- return ioutil.NopCloser(bytes.NewBufferString("dummy")), nil
+ return io.NopCloser(bytes.NewBufferString("dummy")), nil
}
func (a *DummyTransferAdapter) Upload(ctx context.Context, l *Link, p Pointer, r io.Reader) error {
@@ -50,7 +49,7 @@ func lfsTestRoundtripHandler(req *http.Request) *http.Response {
if strings.Contains(url, "status-not-ok") {
return &http.Response{StatusCode: http.StatusBadRequest}
} else if strings.Contains(url, "invalid-json-response") {
- return &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewBufferString("invalid json"))}
+ return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString("invalid json"))}
} else if strings.Contains(url, "valid-batch-request-download") {
batchResponse = &BatchResponse{
Transfer: "dummy",
@@ -149,7 +148,7 @@ func lfsTestRoundtripHandler(req *http.Request) *http.Response {
payload := new(bytes.Buffer)
json.NewEncoder(payload).Encode(batchResponse)
- return &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(payload)}
+ return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(payload)}
}
func TestHTTPClientDownload(t *testing.T) {
@@ -350,7 +349,7 @@ func TestHTTPClientUpload(t *testing.T) {
client.transfers["dummy"] = dummy
err := client.Upload(context.Background(), []Pointer{p}, func(p Pointer, objectError error) (io.ReadCloser, error) {
- return ioutil.NopCloser(new(bytes.Buffer)), objectError
+ return io.NopCloser(new(bytes.Buffer)), objectError
})
if len(c.expectederror) > 0 {
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go
index 9192b486ed..b26d516c68 100644
--- a/modules/lfs/transferadapter_test.go
+++ b/modules/lfs/transferadapter_test.go
@@ -8,7 +8,6 @@ import (
"bytes"
"context"
"io"
- "io/ioutil"
"net/http"
"strings"
"testing"
@@ -35,7 +34,7 @@ func TestBasicTransferAdapter(t *testing.T) {
if strings.Contains(url, "download-request") {
assert.Equal(t, "GET", req.Method)
- return &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewBufferString("dummy"))}
+ return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewBufferString("dummy"))}
} else if strings.Contains(url, "upload-request") {
assert.Equal(t, "PUT", req.Method)
assert.Equal(t, "application/octet-stream", req.Header.Get("Content-Type"))
@@ -63,7 +62,7 @@ func TestBasicTransferAdapter(t *testing.T) {
payload := new(bytes.Buffer)
json.NewEncoder(payload).Encode(er)
- return &http.Response{StatusCode: http.StatusNotFound, Body: ioutil.NopCloser(payload)}
+ return &http.Response{StatusCode: http.StatusNotFound, Body: io.NopCloser(payload)}
} else {
t.Errorf("Unknown test case: %s", url)
return nil
diff --git a/modules/log/conn_test.go b/modules/log/conn_test.go
index dc5de732f4..158a8ca6ce 100644
--- a/modules/log/conn_test.go
+++ b/modules/log/conn_test.go
@@ -6,7 +6,7 @@ package log
import (
"fmt"
- "io/ioutil"
+ "io"
"net"
"strings"
"sync"
@@ -20,7 +20,7 @@ func listenReadAndClose(t *testing.T, l net.Listener, expected string) {
conn, err := l.Accept()
assert.NoError(t, err)
defer conn.Close()
- written, err := ioutil.ReadAll(conn)
+ written, err := io.ReadAll(conn)
assert.NoError(t, err)
assert.Equal(t, expected, string(written))
diff --git a/modules/log/file_test.go b/modules/log/file_test.go
index 7bc5f90037..39d2467a1f 100644
--- a/modules/log/file_test.go
+++ b/modules/log/file_test.go
@@ -7,7 +7,7 @@ package log
import (
"compress/gzip"
"fmt"
- "io/ioutil"
+ "io"
"os"
"path/filepath"
"strings"
@@ -19,7 +19,7 @@ import (
)
func TestFileLoggerFails(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", "TestFileLogger")
+ tmpDir, err := os.MkdirTemp("", "TestFileLogger")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
@@ -47,7 +47,7 @@ func TestFileLoggerFails(t *testing.T) {
}
func TestFileLogger(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", "TestFileLogger")
+ tmpDir, err := os.MkdirTemp("", "TestFileLogger")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
@@ -85,21 +85,21 @@ func TestFileLogger(t *testing.T) {
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err := ioutil.ReadFile(filename)
+ logData, err := os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
event.level = DEBUG
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
event.level = TRACE
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
@@ -107,18 +107,18 @@ func TestFileLogger(t *testing.T) {
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
// Should rotate
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1))
+ logData, err = os.ReadFile(filename + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1))
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
assert.Equal(t, expected, string(logData))
@@ -134,7 +134,7 @@ func TestFileLogger(t *testing.T) {
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
@@ -142,7 +142,7 @@ func TestFileLogger(t *testing.T) {
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
@@ -150,7 +150,7 @@ func TestFileLogger(t *testing.T) {
}
func TestCompressFileLogger(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", "TestFileLogger")
+ tmpDir, err := os.MkdirTemp("", "TestFileLogger")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
@@ -184,7 +184,7 @@ func TestCompressFileLogger(t *testing.T) {
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err := ioutil.ReadFile(filename)
+ logData, err := os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
@@ -192,7 +192,7 @@ func TestCompressFileLogger(t *testing.T) {
expected += fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg)
fileLogger.LogEvent(&event)
fileLogger.Flush()
- logData, err = ioutil.ReadFile(filename)
+ logData, err = os.ReadFile(filename)
assert.NoError(t, err)
assert.Equal(t, expected, string(logData))
@@ -210,7 +210,7 @@ func TestCompressFileLogger(t *testing.T) {
}
func TestCompressOldFile(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", "TestFileLogger")
+ tmpDir, err := os.MkdirTemp("", "TestFileLogger")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
fname := filepath.Join(tmpDir, "test")
@@ -238,9 +238,9 @@ func TestCompressOldFile(t *testing.T) {
assert.NoError(t, err)
zr, err := gzip.NewReader(f)
assert.NoError(t, err)
- data, err := ioutil.ReadAll(zr)
+ data, err := io.ReadAll(zr)
assert.NoError(t, err)
- original, err := ioutil.ReadFile(nonGzip)
+ original, err := os.ReadFile(nonGzip)
assert.NoError(t, err)
assert.Equal(t, original, data)
}
diff --git a/modules/log/stack.go b/modules/log/stack.go
index 568c10cd00..8fc3f35421 100644
--- a/modules/log/stack.go
+++ b/modules/log/stack.go
@@ -7,7 +7,7 @@ package log
import (
"bytes"
"fmt"
- "io/ioutil"
+ "os"
"runtime"
)
@@ -38,7 +38,7 @@ func Stack(skip int) string {
fmt.Fprintf(buf, "%s:%d (0x%x)\n", filename, lineNumber, programCounter)
// Now try to print the offending line
if filename != lastFilename {
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
// can't read this sourcefile
// likely we don't have the sourcecode available
diff --git a/modules/markup/csv/csv.go b/modules/markup/csv/csv.go
index 8a4df89511..e4b423d4f0 100644
--- a/modules/markup/csv/csv.go
+++ b/modules/markup/csv/csv.go
@@ -9,7 +9,6 @@ import (
"bytes"
"html"
"io"
- "io/ioutil"
"regexp"
"strconv"
@@ -87,7 +86,7 @@ func (Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Wri
var tmpBlock = bufio.NewWriter(output)
// FIXME: don't read all to memory
- rawBytes, err := ioutil.ReadAll(input)
+ rawBytes, err := io.ReadAll(input)
if err != nil {
return err
}
diff --git a/modules/markup/external/external.go b/modules/markup/external/external.go
index f7be06dbe9..36cbd69f92 100644
--- a/modules/markup/external/external.go
+++ b/modules/markup/external/external.go
@@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
- "io/ioutil"
"os"
"os/exec"
"runtime"
@@ -75,7 +74,7 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
if p.IsInputFile {
// write to temp file
- f, err := ioutil.TempFile("", "gitea_input")
+ f, err := os.CreateTemp("", "gitea_input")
if err != nil {
return fmt.Errorf("%s create temp file when rendering %s failed: %v", p.Name(), p.Command, err)
}
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 4d6574a596..d5ae237b5b 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -7,7 +7,6 @@ package markup
import (
"bytes"
"io"
- "io/ioutil"
"net/url"
"path"
"path/filepath"
@@ -290,7 +289,7 @@ var nulCleaner = strings.NewReplacer("\000", "")
func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output io.Writer) error {
defer ctx.Cancel()
// FIXME: don't read all content to memory
- rawHTML, err := ioutil.ReadAll(input)
+ rawHTML, err := io.ReadAll(input)
if err != nil {
return err
}
diff --git a/modules/markup/markdown/markdown.go b/modules/markup/markdown/markdown.go
index ab026dd1b8..554ee0d4be 100644
--- a/modules/markup/markdown/markdown.go
+++ b/modules/markup/markdown/markdown.go
@@ -8,7 +8,6 @@ package markdown
import (
"fmt"
"io"
- "io/ioutil"
"strings"
"sync"
@@ -189,7 +188,7 @@ func actualRender(ctx *markup.RenderContext, input io.Reader, output io.Writer)
// FIXME: Don't read all to memory, but goldmark doesn't support
pc := newParserContext(ctx)
- buf, err := ioutil.ReadAll(input)
+ buf, err := io.ReadAll(input)
if err != nil {
log.Error("Unable to ReadAll: %v", err)
return
diff --git a/modules/migrations/restore.go b/modules/migrations/restore.go
index 6287d601c2..5fddf7b505 100644
--- a/modules/migrations/restore.go
+++ b/modules/migrations/restore.go
@@ -7,7 +7,6 @@ package migrations
import (
"context"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strconv"
@@ -55,7 +54,7 @@ func (r *RepositoryRestorer) SetContext(ctx context.Context) {
func (r *RepositoryRestorer) getRepoOptions() (map[string]string, error) {
p := filepath.Join(r.baseDir, "repo.yml")
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
@@ -96,7 +95,7 @@ func (r *RepositoryRestorer) GetTopics() ([]string, error) {
Topics []string `yaml:"topics"`
}{}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
@@ -120,7 +119,7 @@ func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) {
return nil, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
@@ -144,7 +143,7 @@ func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) {
return nil, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
@@ -175,7 +174,7 @@ func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) {
return nil, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
@@ -199,7 +198,7 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool,
return nil, false, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, false, err
}
@@ -226,7 +225,7 @@ func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.C
return nil, false, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, false, err
}
@@ -250,7 +249,7 @@ func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullReq
return nil, false, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, false, err
}
@@ -278,7 +277,7 @@ func (r *RepositoryRestorer) GetReviews(context base.IssueContext) ([]*base.Revi
return nil, err
}
- bs, err := ioutil.ReadFile(p)
+ bs, err := os.ReadFile(p)
if err != nil {
return nil, err
}
diff --git a/modules/options/dynamic.go b/modules/options/dynamic.go
index 13fa5d6aa7..78b0450d9b 100644
--- a/modules/options/dynamic.go
+++ b/modules/options/dynamic.go
@@ -9,7 +9,7 @@ package options
import (
"fmt"
- "io/ioutil"
+ "os"
"path"
"code.gitea.io/gitea/modules/log"
@@ -100,7 +100,7 @@ func fileFromDir(name string) ([]byte, error) {
log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
}
if isFile {
- return ioutil.ReadFile(customPath)
+ return os.ReadFile(customPath)
}
staticPath := path.Join(setting.StaticRootPath, "options", name)
@@ -110,7 +110,7 @@ func fileFromDir(name string) ([]byte, error) {
log.Error("Unable to check if %s is a file. Error: %v", staticPath, err)
}
if isFile {
- return ioutil.ReadFile(staticPath)
+ return os.ReadFile(staticPath)
}
return []byte{}, fmt.Errorf("Asset file does not exist: %s", name)
diff --git a/modules/options/static.go b/modules/options/static.go
index 49e8445cd5..afe32216d3 100644
--- a/modules/options/static.go
+++ b/modules/options/static.go
@@ -9,7 +9,8 @@ package options
import (
"fmt"
- "io/ioutil"
+ "io"
+ "os"
"path"
"code.gitea.io/gitea/modules/log"
@@ -109,7 +110,7 @@ func fileFromDir(name string) ([]byte, error) {
log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
}
if isFile {
- return ioutil.ReadFile(customPath)
+ return os.ReadFile(customPath)
}
f, err := Assets.Open(name)
@@ -118,7 +119,7 @@ func fileFromDir(name string) ([]byte, error) {
}
defer f.Close()
- return ioutil.ReadAll(f)
+ return io.ReadAll(f)
}
func Asset(name string) ([]byte, error) {
@@ -127,7 +128,7 @@ func Asset(name string) ([]byte, error) {
return nil, err
}
defer f.Close()
- return ioutil.ReadAll(f)
+ return io.ReadAll(f)
}
func AssetNames() []string {
diff --git a/modules/pprof/pprof.go b/modules/pprof/pprof.go
index 80ad67be3a..f080728766 100644
--- a/modules/pprof/pprof.go
+++ b/modules/pprof/pprof.go
@@ -6,7 +6,7 @@ package pprof
import (
"fmt"
- "io/ioutil"
+ "os"
"runtime"
"runtime/pprof"
@@ -15,7 +15,7 @@ import (
// DumpMemProfileForUsername dumps a memory profile at pprofDataPath as memprofile_<username>_<temporary id>
func DumpMemProfileForUsername(pprofDataPath, username string) error {
- f, err := ioutil.TempFile(pprofDataPath, fmt.Sprintf("memprofile_%s_", username))
+ f, err := os.CreateTemp(pprofDataPath, fmt.Sprintf("memprofile_%s_", username))
if err != nil {
return err
}
@@ -27,7 +27,7 @@ func DumpMemProfileForUsername(pprofDataPath, username string) error {
// DumpCPUProfileForUsername dumps a CPU profile at pprofDataPath as cpuprofile_<username>_<temporary id>
// it returns the stop function which stops, writes and closes the CPU profile file
func DumpCPUProfileForUsername(pprofDataPath, username string) (func(), error) {
- f, err := ioutil.TempFile(pprofDataPath, fmt.Sprintf("cpuprofile_%s_", username))
+ f, err := os.CreateTemp(pprofDataPath, fmt.Sprintf("cpuprofile_%s_", username))
if err != nil {
return nil, err
}
diff --git a/modules/private/key.go b/modules/private/key.go
index d0b11a96e7..8dfd82a6d6 100644
--- a/modules/private/key.go
+++ b/modules/private/key.go
@@ -7,7 +7,7 @@ package private
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"code.gitea.io/gitea/modules/setting"
@@ -49,7 +49,7 @@ func AuthorizedPublicKeyByContent(ctx context.Context, content string) (string,
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Failed to update public key: %s", decodeJSONError(resp).Err)
}
- bs, err := ioutil.ReadAll(resp.Body)
+ bs, err := io.ReadAll(resp.Body)
return string(bs), err
}
diff --git a/modules/private/mail.go b/modules/private/mail.go
index 7e229396e3..bcf601b029 100644
--- a/modules/private/mail.go
+++ b/modules/private/mail.go
@@ -7,7 +7,7 @@ package private
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"code.gitea.io/gitea/modules/json"
@@ -45,7 +45,7 @@ func SendEmail(ctx context.Context, subject, message string, to []string) (int,
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
return http.StatusInternalServerError, fmt.Sprintf("Response body error: %v", err.Error())
}
diff --git a/modules/private/restore_repo.go b/modules/private/restore_repo.go
index b5592278ab..6ebf4c63d5 100644
--- a/modules/private/restore_repo.go
+++ b/modules/private/restore_repo.go
@@ -7,7 +7,7 @@ package private
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"time"
@@ -47,7 +47,7 @@ func RestoreRepo(ctx context.Context, repoDir, ownerName, repoName string, units
var ret = struct {
Err string `json:"err"`
}{}
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
return http.StatusInternalServerError, fmt.Sprintf("Response body error: %v", err.Error())
}
diff --git a/modules/public/static.go b/modules/public/static.go
index 6994ed6508..32ba0fe258 100644
--- a/modules/public/static.go
+++ b/modules/public/static.go
@@ -11,7 +11,6 @@ import (
"bytes"
"compress/gzip"
"io"
- "io/ioutil"
"mime"
"net/http"
"os"
@@ -31,7 +30,7 @@ func Asset(name string) ([]byte, error) {
return nil, err
}
defer f.Close()
- return ioutil.ReadAll(f)
+ return io.ReadAll(f)
}
func AssetNames() []string {
diff --git a/modules/queue/queue_disk_channel_test.go b/modules/queue/queue_disk_channel_test.go
index 06cb7a7a96..99fb65934e 100644
--- a/modules/queue/queue_disk_channel_test.go
+++ b/modules/queue/queue_disk_channel_test.go
@@ -5,7 +5,7 @@
package queue
import (
- "io/ioutil"
+ "os"
"sync"
"testing"
@@ -26,7 +26,7 @@ func TestPersistableChannelQueue(t *testing.T) {
queueShutdown := []func(){}
queueTerminate := []func(){}
- tmpDir, err := ioutil.TempDir("", "persistable-channel-queue-test-data")
+ tmpDir, err := os.MkdirTemp("", "persistable-channel-queue-test-data")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
diff --git a/modules/queue/queue_disk_test.go b/modules/queue/queue_disk_test.go
index 1f884d4f8d..549a04104e 100644
--- a/modules/queue/queue_disk_test.go
+++ b/modules/queue/queue_disk_test.go
@@ -5,7 +5,7 @@
package queue
import (
- "io/ioutil"
+ "os"
"sync"
"testing"
"time"
@@ -28,7 +28,7 @@ func TestLevelQueue(t *testing.T) {
queueShutdown := []func(){}
queueTerminate := []func(){}
- tmpDir, err := ioutil.TempDir("", "level-queue-test-data")
+ tmpDir, err := os.MkdirTemp("", "level-queue-test-data")
assert.NoError(t, err)
defer util.RemoveAll(tmpDir)
diff --git a/modules/recaptcha/recaptcha.go b/modules/recaptcha/recaptcha.go
index e0f5ee2e07..c6798f7117 100644
--- a/modules/recaptcha/recaptcha.go
+++ b/modules/recaptcha/recaptcha.go
@@ -7,7 +7,7 @@ package recaptcha
import (
"context"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"strings"
@@ -46,7 +46,7 @@ func Verify(ctx context.Context, response string) (bool, error) {
return false, fmt.Errorf("Failed to send CAPTCHA response: %s", err)
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
return false, fmt.Errorf("Failed to read CAPTCHA response: %s", err)
}
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index 6ac2a3051c..8ab518add5 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -6,7 +6,6 @@ package repository
import (
"fmt"
- "io/ioutil"
"os"
"path"
"path/filepath"
@@ -85,7 +84,7 @@ func checkGiteaTemplate(tmpDir string) (*models.GiteaTemplate, error) {
return nil, err
}
- content, err := ioutil.ReadFile(gtPath)
+ content, err := os.ReadFile(gtPath)
if err != nil {
return nil, err
}
@@ -151,12 +150,12 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
base := strings.TrimPrefix(filepath.ToSlash(path), tmpDirSlash)
for _, g := range gt.Globs() {
if g.Match(base) {
- content, err := ioutil.ReadFile(path)
+ content, err := os.ReadFile(path)
if err != nil {
return err
}
- if err := ioutil.WriteFile(path,
+ if err := os.WriteFile(path,
[]byte(generateExpansion(string(content), templateRepo, generateRepo)),
0644); err != nil {
return err
@@ -187,7 +186,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
}
func generateGitContent(ctx *db.Context, repo, templateRepo, generateRepo *models.Repository) (err error) {
- tmpDir, err := ioutil.TempDir(os.TempDir(), "gitea-"+repo.Name)
+ tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name)
if err != nil {
return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
}
diff --git a/modules/repository/hooks.go b/modules/repository/hooks.go
index de5df591f0..e219903f75 100644
--- a/modules/repository/hooks.go
+++ b/modules/repository/hooks.go
@@ -7,7 +7,6 @@ package repository
import (
"context"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
@@ -110,7 +109,7 @@ func createDelegateHooks(repoPath string) (err error) {
if err = util.Remove(oldHookPath); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %v ", oldHookPath, err)
}
- if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
+ if err = os.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
}
@@ -121,7 +120,7 @@ func createDelegateHooks(repoPath string) (err error) {
if err = util.Remove(newHookPath); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %v", newHookPath, err)
}
- if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
+ if err = os.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
}
@@ -192,7 +191,7 @@ func CheckDelegateHooks(repoPath string) ([]string, error) {
if cont {
continue
}
- contents, err := ioutil.ReadFile(oldHookPath)
+ contents, err := os.ReadFile(oldHookPath)
if err != nil {
return results, err
}
@@ -202,7 +201,7 @@ func CheckDelegateHooks(repoPath string) ([]string, error) {
if !checkExecutable(oldHookPath) {
results = append(results, fmt.Sprintf("old hook file %s is not executable", oldHookPath))
}
- contents, err = ioutil.ReadFile(newHookPath)
+ contents, err = os.ReadFile(newHookPath)
if err != nil {
return results, err
}
diff --git a/modules/repository/init.go b/modules/repository/init.go
index e42d35a971..2a86e964ca 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -7,7 +7,6 @@ package repository
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -59,7 +58,7 @@ func prepareRepoCommit(ctx *db.Context, repo *models.Repository, tmpDir, repoPat
"CloneURL.HTTPS": cloneLink.HTTPS,
"OwnerName": repo.OwnerName,
}
- if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
+ if err = os.WriteFile(filepath.Join(tmpDir, "README.md"),
[]byte(com.Expand(string(data), match)), 0644); err != nil {
return fmt.Errorf("write README.md: %v", err)
}
@@ -79,7 +78,7 @@ func prepareRepoCommit(ctx *db.Context, repo *models.Repository, tmpDir, repoPat
}
if buf.Len() > 0 {
- if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
+ if err = os.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
return fmt.Errorf("write .gitignore: %v", err)
}
}
@@ -92,7 +91,7 @@ func prepareRepoCommit(ctx *db.Context, repo *models.Repository, tmpDir, repoPat
return fmt.Errorf("GetRepoInitFile[%s]: %v", opts.License, err)
}
- if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
+ if err = os.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
return fmt.Errorf("write LICENSE: %v", err)
}
}
@@ -291,7 +290,7 @@ func initRepository(ctx *db.Context, repoPath string, u *models.User, repo *mode
// Initialize repository according to user's choice.
if opts.AutoInit {
- tmpDir, err := ioutil.TempDir(os.TempDir(), "gitea-"+repo.Name)
+ tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name)
if err != nil {
return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 02f5cd8548..b054f27c59 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -9,7 +9,6 @@ import (
"encoding/base64"
"fmt"
"io"
- "io/ioutil"
"math"
"net"
"net/url"
@@ -764,7 +763,7 @@ func NewContext() {
if len(trustedUserCaKeys) > 0 && SSH.AuthorizedPrincipalsEnabled {
fname := sec.Key("SSH_TRUSTED_USER_CA_KEYS_FILENAME").MustString(filepath.Join(SSH.RootPath, "gitea-trusted-user-ca-keys.pem"))
- if err := ioutil.WriteFile(fname,
+ if err := os.WriteFile(fname,
[]byte(strings.Join(trustedUserCaKeys, "\n")), 0600); err != nil {
log.Fatal("Failed to create '%s': %v", fname, err)
}
@@ -1030,7 +1029,7 @@ func loadInternalToken(sec *ini.Section) string {
}
defer fp.Close()
- buf, err := ioutil.ReadAll(fp)
+ buf, err := io.ReadAll(fp)
if err != nil {
log.Fatal("Failed to read InternalTokenURI (%s): %v", uri, err)
}
diff --git a/modules/storage/local.go b/modules/storage/local.go
index 1329f722c2..54e0d0563d 100644
--- a/modules/storage/local.go
+++ b/modules/storage/local.go
@@ -7,7 +7,6 @@ package storage
import (
"context"
"io"
- "io/ioutil"
"net/url"
"os"
"path/filepath"
@@ -76,7 +75,7 @@ func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)
if err := os.MkdirAll(l.tmpdir, os.ModePerm); err != nil {
return 0, err
}
- tmp, err := ioutil.TempFile(l.tmpdir, "upload-*")
+ tmp, err := os.CreateTemp(l.tmpdir, "upload-*")
if err != nil {
return 0, err
}
diff --git a/modules/svg/discover_nobindata.go b/modules/svg/discover_nobindata.go
index 8d857551dc..e3f13ddf6c 100644
--- a/modules/svg/discover_nobindata.go
+++ b/modules/svg/discover_nobindata.go
@@ -8,7 +8,7 @@
package svg
import (
- "io/ioutil"
+ "os"
"path/filepath"
"code.gitea.io/gitea/modules/setting"
@@ -20,7 +20,7 @@ func Discover() map[string]string {
files, _ := filepath.Glob(filepath.Join(setting.StaticRootPath, "public", "img", "svg", "*.svg"))
for _, file := range files {
- content, err := ioutil.ReadFile(file)
+ content, err := os.ReadFile(file)
if err == nil {
filename := filepath.Base(file)
svgs[filename[:len(filename)-4]] = string(content)
diff --git a/modules/templates/dynamic.go b/modules/templates/dynamic.go
index 4732fce421..fde58a4a70 100644
--- a/modules/templates/dynamic.go
+++ b/modules/templates/dynamic.go
@@ -9,7 +9,6 @@ package templates
import (
"html/template"
- "io/ioutil"
"os"
"path"
"path/filepath"
@@ -28,14 +27,14 @@ var (
// GetAsset returns asset content via name
func GetAsset(name string) ([]byte, error) {
- bs, err := ioutil.ReadFile(filepath.Join(setting.CustomPath, name))
+ bs, err := os.ReadFile(filepath.Join(setting.CustomPath, name))
if err != nil && !os.IsNotExist(err) {
return nil, err
} else if err == nil {
return bs, nil
}
- return ioutil.ReadFile(filepath.Join(setting.StaticRootPath, name))
+ return os.ReadFile(filepath.Join(setting.StaticRootPath, name))
}
// GetAssetNames returns assets list
@@ -71,7 +70,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
continue
}
- content, err := ioutil.ReadFile(path.Join(staticDir, filePath))
+ content, err := os.ReadFile(path.Join(staticDir, filePath))
if err != nil {
log.Warn("Failed to read static %s template. %v", filePath, err)
@@ -100,7 +99,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
continue
}
- content, err := ioutil.ReadFile(path.Join(customDir, filePath))
+ content, err := os.ReadFile(path.Join(customDir, filePath))
if err != nil {
log.Warn("Failed to read custom %s template. %v", filePath, err)
diff --git a/modules/templates/static.go b/modules/templates/static.go
index ee20b2af3b..fdd68c1e6a 100644
--- a/modules/templates/static.go
+++ b/modules/templates/static.go
@@ -9,7 +9,7 @@ package templates
import (
"html/template"
- "io/ioutil"
+ "io"
"os"
"path"
"path/filepath"
@@ -28,7 +28,7 @@ var (
// GetAsset get a special asset, only for chi
func GetAsset(name string) ([]byte, error) {
- bs, err := ioutil.ReadFile(filepath.Join(setting.CustomPath, name))
+ bs, err := os.ReadFile(filepath.Join(setting.CustomPath, name))
if err != nil && !os.IsNotExist(err) {
return nil, err
} else if err == nil {
@@ -103,7 +103,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
continue
}
- content, err := ioutil.ReadFile(path.Join(customDir, filePath))
+ content, err := os.ReadFile(path.Join(customDir, filePath))
if err != nil {
log.Warn("Failed to read custom %s template. %v", filePath, err)
@@ -130,7 +130,7 @@ func Asset(name string) ([]byte, error) {
return nil, err
}
defer f.Close()
- return ioutil.ReadAll(f)
+ return io.ReadAll(f)
}
func AssetNames() []string {