Replace deprecated ioutil with io and os (#20776)
* Replace ioutil with io and os * Replace ioutil in utils/file.go * Minor fix to tests and excluded files Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
15b6046a62
Коммит
b4570afa90
@@ -6,7 +6,6 @@ package filestore
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -38,7 +37,7 @@ func TestLocalFileBackendTestSuite(t *testing.T) {
|
||||
|
||||
mlog.InitGlobalLogger(logger)
|
||||
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ package filestore
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -88,7 +87,7 @@ func (b *LocalFileBackend) Reader(path string) (ReadCloseSeeker, error) {
|
||||
}
|
||||
|
||||
func (b *LocalFileBackend) ReadFile(path string) ([]byte, error) {
|
||||
f, err := ioutil.ReadFile(filepath.Join(b.directory, path))
|
||||
f, err := os.ReadFile(filepath.Join(b.directory, path))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to read file %s", path)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -241,7 +240,7 @@ func (b *S3FileBackend) ReadFile(path string) ([]byte, error) {
|
||||
}
|
||||
|
||||
defer minioObject.Close()
|
||||
f, err := ioutil.ReadAll(minioObject)
|
||||
f, err := io.ReadAll(minioObject)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to read file %s", path)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ package i18n
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -59,7 +59,7 @@ func InitTranslations(serverLocale, clientLocale string) error {
|
||||
}
|
||||
|
||||
func initTranslationsWithDir(dir string) error {
|
||||
files, _ := ioutil.ReadDir(dir)
|
||||
files, _ := os.ReadDir(dir)
|
||||
for _, f := range files {
|
||||
if filepath.Ext(f.Name()) == ".json" {
|
||||
filename := f.Name()
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/mail"
|
||||
"net/smtp"
|
||||
@@ -195,12 +194,12 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) {
|
||||
DeleteMailBox("test2@example.com")
|
||||
|
||||
// create two files with the same name that will both be attached to the email
|
||||
file1, err := ioutil.TempFile("", "*")
|
||||
file1, err := os.CreateTemp("", "*")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(file1.Name())
|
||||
file1.Write([]byte("hello world"))
|
||||
file1.Close()
|
||||
file2, err := ioutil.TempFile("", "*")
|
||||
file2, err := os.CreateTemp("", "*")
|
||||
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(file2.Name())
|
||||
@@ -326,7 +325,7 @@ func (m *mockMailer) Write(p []byte) (int, error) {
|
||||
func (m *mockMailer) Close() error { return nil }
|
||||
|
||||
func TestSendMail(t *testing.T) {
|
||||
dir, err := ioutil.TempDir(".", "mail-test-")
|
||||
dir, err := os.MkdirTemp(".", "mail-test-")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
mocm := &mockMailer{}
|
||||
|
||||
@@ -6,7 +6,6 @@ package mlog_test
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -99,7 +98,7 @@ func TestLoggingAfterInitialized(t *testing.T) {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
var filePath string
|
||||
if testCase.cfg.Type == "file" {
|
||||
tempDir, err := ioutil.TempDir(os.TempDir(), "TestLoggingAfterInitialized")
|
||||
tempDir, err := os.MkdirTemp(os.TempDir(), "TestLoggingAfterInitialized")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(tempDir)
|
||||
|
||||
@@ -122,7 +121,7 @@ func TestLoggingAfterInitialized(t *testing.T) {
|
||||
logger.Shutdown()
|
||||
|
||||
if testCase.cfg.Type == "file" {
|
||||
logs, err := ioutil.ReadFile(filePath)
|
||||
logs, err := os.ReadFile(filePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
actual := strings.TrimSpace(string(logs))
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -181,12 +180,14 @@ func NewLogger(options ...Option) (*Logger, error) {
|
||||
|
||||
// Configure provides a new configuration for this logger.
|
||||
// Zero or more sources of config can be provided:
|
||||
// cfgFile - path to file containing JSON
|
||||
// cfgEscaped - JSON string probably from ENV var
|
||||
//
|
||||
// cfgFile - path to file containing JSON
|
||||
// cfgEscaped - JSON string probably from ENV var
|
||||
//
|
||||
// For each case JSON containing log targets is provided. Target name collisions are resolved
|
||||
// using the following precedence:
|
||||
// cfgFile > cfgEscaped
|
||||
//
|
||||
// cfgFile > cfgEscaped
|
||||
//
|
||||
// An optional set of factories can be provided which will be called to create any target
|
||||
// types or formatters not built-in.
|
||||
@@ -199,7 +200,7 @@ func (l *Logger) Configure(cfgFile string, cfgEscaped string, factories *Factori
|
||||
|
||||
// Add config from file
|
||||
if cfgFile != "" {
|
||||
b, err := ioutil.ReadFile(cfgFile)
|
||||
b, err := os.ReadFile(cfgFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading logger config file %s: %w", cfgFile, err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package templates
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -17,12 +16,12 @@ import (
|
||||
)
|
||||
|
||||
func TestHTMLTemplateWatcher(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
require.NoError(t, os.Mkdir(filepath.Join(dir, "templates"), 0700))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "templates", "foo.html"), []byte(`{{ define "foo" }}foo{{ end }}`), 0600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "templates", "foo.html"), []byte(`{{ define "foo" }}foo{{ end }}`), 0600))
|
||||
|
||||
prevDir, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
@@ -45,7 +44,7 @@ func TestHTMLTemplateWatcher(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "foo", text)
|
||||
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "templates", "foo.html"), []byte(`{{ define "foo" }}bar{{ end }}`), 0600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "templates", "foo.html"), []byte(`{{ define "foo" }}bar{{ end }}`), 0600))
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
text, err := watcher.RenderToString("foo", Data{})
|
||||
|
||||
Ссылка в новой задаче
Block a user