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
@@ -7,7 +7,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -25,7 +24,7 @@ func (ae *archiveExtractor) Match(filename string) bool {
|
||||
}
|
||||
|
||||
func (ae *archiveExtractor) Extract(name string, r io.ReadSeeker) (string, error) {
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "archiver")
|
||||
dir, err := os.MkdirTemp(os.TempDir(), "archiver")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error creating temporary file: %v", err)
|
||||
}
|
||||
@@ -49,7 +48,7 @@ func (ae *archiveExtractor) Extract(name string, r io.ReadSeeker) (string, error
|
||||
filename = strings.ReplaceAll(filename, "-", " ")
|
||||
filename = strings.ReplaceAll(filename, ".", " ")
|
||||
filename = strings.ReplaceAll(filename, ",", " ")
|
||||
data, err2 := ioutil.ReadAll(file)
|
||||
data, err2 := io.ReadAll(file)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ package docextractor
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"path"
|
||||
@@ -63,7 +62,7 @@ func (mpe *mmPreviewExtractor) Extract(filename string, file io.ReadSeeker) (str
|
||||
if resp.StatusCode != 200 {
|
||||
return "", errors.New("Unable to generate file preview using mmpreview (The server has replied with an error)")
|
||||
}
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "unable to read the response from mmpreview")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -33,7 +32,7 @@ func (pe *pdfExtractor) Extract(filename string, r io.ReadSeeker) (out string, o
|
||||
outErr = errors.New("error extracting pdf text")
|
||||
}
|
||||
}()
|
||||
f, err := ioutil.TempFile(os.TempDir(), "pdflib")
|
||||
f, err := os.CreateTemp(os.TempDir(), "pdflib")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error creating temporary file: %v", err)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package docextractor
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -47,6 +46,6 @@ func (pe *plainExtractor) Extract(filename string, r io.ReadSeeker) (string, err
|
||||
}
|
||||
}
|
||||
|
||||
text, _ := ioutil.ReadAll(r)
|
||||
text, _ := io.ReadAll(r)
|
||||
return string(runes[0:total]) + string(text), nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user