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>
Этот коммит содержится в:
Tim Scheuermann
2022-08-09 14:25:46 +03:00
коммит произвёл GitHub
родитель 15b6046a62
Коммит b4570afa90
115 изменённых файлов: 408 добавлений и 475 удалений

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
@@ -63,7 +62,7 @@ func UpdateAssetsSubpathInDir(subpath, directory string) error {
}
rootHTMLPath := filepath.Join(staticDir, "root.html")
oldRootHTML, err := ioutil.ReadFile(rootHTMLPath)
oldRootHTML, err := os.ReadFile(rootHTMLPath)
if err != nil {
return errors.Wrap(err, "failed to open root.html")
}
@@ -113,19 +112,19 @@ func UpdateAssetsSubpathInDir(subpath, directory string) error {
}
// Write out the updated root.html.
if err = ioutil.WriteFile(rootHTMLPath, []byte(newRootHTML), 0); err != nil {
if err = os.WriteFile(rootHTMLPath, []byte(newRootHTML), 0); err != nil {
return errors.Wrapf(err, "failed to update root.html with subpath %s", subpath)
}
// Rewrite the manifest.json and *.css references to `/static/*` (or a previously rewritten subpath).
err = filepath.Walk(staticDir, func(walkPath string, info os.FileInfo, err error) error {
if filepath.Base(walkPath) == "manifest.json" || filepath.Ext(walkPath) == ".css" {
old, err := ioutil.ReadFile(walkPath)
old, err := os.ReadFile(walkPath)
if err != nil {
return errors.Wrapf(err, "failed to open %s", walkPath)
}
new := strings.Replace(string(old), pathToReplace, newPath, -1)
if err = ioutil.WriteFile(walkPath, []byte(new), 0); err != nil {
if err = os.WriteFile(walkPath, []byte(new), 0); err != nil {
return errors.Wrapf(err, "failed to update %s with subpath %s", walkPath, subpath)
}
}