refactor(plugins): replace deprecated io/ioutil functions

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2023-12-22 01:59:22 +08:00
parent e6953d60e9
commit 1d186a5a81
16 changed files with 32 additions and 41 deletions

View File

@@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"regexp"
@@ -280,7 +280,7 @@ func DokkuApps() ([]string, error) {
func UnfilteredDokkuApps() ([]string, error) {
apps := []string{}
dokkuRoot := MustGetEnv("DOKKU_ROOT")
files, err := ioutil.ReadDir(dokkuRoot)
files, err := os.ReadDir(dokkuRoot)
if err != nil {
return apps, fmt.Errorf("You haven't deployed any applications yet")
}
@@ -517,7 +517,7 @@ func SuppressOutput(f errfunc) error {
err := f()
w.Close()
out, _ := ioutil.ReadAll(r)
out, _ := io.ReadAll(r)
os.Stdout = rescueStdout
if err != nil {

View File

@@ -1,7 +1,6 @@
package common
import (
"io/ioutil"
"os"
"strings"
"testing"
@@ -31,7 +30,7 @@ func setupTests() (err error) {
func setupTestApp() (err error) {
Expect(os.MkdirAll(testAppDir, 0644)).To(Succeed())
b := []byte(testEnvLine + "\n")
if err = ioutil.WriteFile(testEnvFile, b, 0644); err != nil {
if err = os.WriteFile(testEnvFile, b, 0644); err != nil {
return
}
return
@@ -40,7 +39,7 @@ func setupTestApp() (err error) {
func setupTestApp2() (err error) {
Expect(os.MkdirAll(testAppDir2, 0644)).To(Succeed())
b := []byte(testEnvLine2 + "\n")
if err = ioutil.WriteFile(testEnvFile2, b, 0644); err != nil {
if err = os.WriteFile(testEnvFile2, b, 0644); err != nil {
return
}
return

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
@@ -79,7 +78,7 @@ func CopyFromImage(appName string, image string, source string, destination stri
}
}
tmpFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("dokku-%s-%s", MustGetEnv("DOKKU_PID"), "CopyFromImage"))
tmpFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("dokku-%s-%s", MustGetEnv("DOKKU_PID"), "CopyFromImage"))
if err != nil {
return fmt.Errorf("Cannot create temporary file: %v", err)
}

View File

@@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"os/user"
"strconv"
@@ -133,7 +132,7 @@ func IsAbsPath(path string) bool {
// ListFilesWithPrefix lists files within a given path that have a given prefix
func ListFilesWithPrefix(path string, prefix string) []string {
names, err := ioutil.ReadDir(path)
names, err := os.ReadDir(path)
if err != nil {
return []string{}
}
@@ -144,7 +143,7 @@ func ListFilesWithPrefix(path string, prefix string) []string {
continue
}
if f.Mode().IsRegular() {
if f.Type().IsRegular() {
files = append(files, fmt.Sprintf("%s/%s", path, f.Name()))
}
}

View File

@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -115,7 +114,7 @@ func PropertyGetAll(pluginName string, appName string) (map[string]string, error
return properties, errors.New("Specified property path is not a directory")
}
files, err := ioutil.ReadDir(pluginAppConfigRoot)
files, err := os.ReadDir(pluginAppConfigRoot)
if err != nil {
return properties, err
}
@@ -139,7 +138,7 @@ func PropertyGetDefault(pluginName, appName, property, defaultValue string) (val
}
propertyPath := getPropertyPath(pluginName, appName, property)
b, err := ioutil.ReadFile(propertyPath)
b, err := os.ReadFile(propertyPath)
if err != nil {
LogWarn(fmt.Sprintf("Unable to read %s property %s.%s", pluginName, appName, property))
return

View File

@@ -2,7 +2,7 @@ package common
import (
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path/filepath"
@@ -104,8 +104,8 @@ func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
wE.Close()
wO.Close()
readStderr, _ := ioutil.ReadAll(rE)
readStdout, _ := ioutil.ReadAll(rO)
readStderr, _ := io.ReadAll(rE)
readStdout, _ := io.ReadAll(rO)
stderr := string(readStderr[:])
if err != nil {