mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
refactor: move from io/ioutil to io and os package (#1772)
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>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
@@ -108,10 +107,10 @@ func EmptyDir(path string) error {
|
||||
// ListDir will return the contents of a given directory path as a string slice
|
||||
func ListDir(path string) ([]string, error) {
|
||||
var dirPaths []string
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
path = filepath.Dir(path)
|
||||
files, err = ioutil.ReadDir(path)
|
||||
files, err = os.ReadDir(path)
|
||||
if err != nil {
|
||||
return dirPaths, err
|
||||
}
|
||||
@@ -196,7 +195,7 @@ func WriteFile(path string, file []byte) error {
|
||||
return fmt.Errorf("cannot ensure path %s", pathErr)
|
||||
}
|
||||
|
||||
err := ioutil.WriteFile(path, file, 0755)
|
||||
err := os.WriteFile(path, file, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write error for thumbnail %s: %s ", path, err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -53,11 +52,11 @@ func TestDirExists(t *testing.T) {
|
||||
const st = "stash_tmp"
|
||||
|
||||
tmp := os.TempDir()
|
||||
tmpDir, err := ioutil.TempDir(tmp, st) // create a tmp dir in the system's tmp folder
|
||||
tmpDir, err := os.MkdirTemp(tmp, st) // create a tmp dir in the system's tmp folder
|
||||
if err == nil {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
tmpFile, err := ioutil.TempFile(tmpDir, st)
|
||||
tmpFile, err := os.CreateTemp(tmpDir, st)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -66,7 +66,7 @@ func ReadImageFromURL(url string) ([]byte, error) {
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user