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:
parent
aa631d8cd1
commit
f2e7d5477f
103 changed files with 261 additions and 314 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
3
modules/markup/external/external.go
vendored
3
modules/markup/external/external.go
vendored
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue