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:
16 files changed
+32
-41
No files matched your search
@@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -85,7 +84,7 @@ func getAppJSON(appName string) (AppJSON, error) {
|
|||||||
return AppJSON{}, nil
|
return AppJSON{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(getProcessSpecificAppJSONPath(appName))
|
b, err := os.ReadFile(getProcessSpecificAppJSONPath(appName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AppJSON{}, fmt.Errorf("Cannot read app.json file: %v", err)
|
return AppJSON{}, fmt.Errorf("Cannot read app.json file: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package builder
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -35,7 +34,7 @@ func listImagesByImageRepo(imageRepo string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeAllContents(basePath string) error {
|
func removeAllContents(basePath string) error {
|
||||||
dir, err := ioutil.ReadDir(basePath)
|
dir, err := os.ReadDir(basePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package builder
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -71,7 +70,7 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
|||||||
return fmt.Errorf("Specified build-dir not found in sourcecode working directory: %v", buildDir)
|
return fmt.Errorf("Specified build-dir not found in sourcecode working directory: %v", buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpWorkDir, err := ioutil.TempDir(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "CorePostExtract"))
|
tmpWorkDir, err := os.MkdirTemp(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "CorePostExtract"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to create temporary working directory: %v", err.Error())
|
return fmt.Errorf("Unable to create temporary working directory: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -280,7 +280,7 @@ func DokkuApps() ([]string, error) {
|
|||||||
func UnfilteredDokkuApps() ([]string, error) {
|
func UnfilteredDokkuApps() ([]string, error) {
|
||||||
apps := []string{}
|
apps := []string{}
|
||||||
dokkuRoot := MustGetEnv("DOKKU_ROOT")
|
dokkuRoot := MustGetEnv("DOKKU_ROOT")
|
||||||
files, err := ioutil.ReadDir(dokkuRoot)
|
files, err := os.ReadDir(dokkuRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
||||||
}
|
}
|
||||||
@@ -517,7 +517,7 @@ func SuppressOutput(f errfunc) error {
|
|||||||
err := f()
|
err := f()
|
||||||
|
|
||||||
w.Close()
|
w.Close()
|
||||||
out, _ := ioutil.ReadAll(r)
|
out, _ := io.ReadAll(r)
|
||||||
os.Stdout = rescueStdout
|
os.Stdout = rescueStdout
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -31,7 +30,7 @@ func setupTests() (err error) {
|
|||||||
func setupTestApp() (err error) {
|
func setupTestApp() (err error) {
|
||||||
Expect(os.MkdirAll(testAppDir, 0644)).To(Succeed())
|
Expect(os.MkdirAll(testAppDir, 0644)).To(Succeed())
|
||||||
b := []byte(testEnvLine + "\n")
|
b := []byte(testEnvLine + "\n")
|
||||||
if err = ioutil.WriteFile(testEnvFile, b, 0644); err != nil {
|
if err = os.WriteFile(testEnvFile, b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -40,7 +39,7 @@ func setupTestApp() (err error) {
|
|||||||
func setupTestApp2() (err error) {
|
func setupTestApp2() (err error) {
|
||||||
Expect(os.MkdirAll(testAppDir2, 0644)).To(Succeed())
|
Expect(os.MkdirAll(testAppDir2, 0644)).To(Succeed())
|
||||||
b := []byte(testEnvLine2 + "\n")
|
b := []byte(testEnvLine2 + "\n")
|
||||||
if err = ioutil.WriteFile(testEnvFile2, b, 0644); err != nil {
|
if err = os.WriteFile(testEnvFile2, b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Cannot create temporary file: %v", err)
|
return fmt.Errorf("Cannot create temporary file: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -133,7 +132,7 @@ func IsAbsPath(path string) bool {
|
|||||||
|
|
||||||
// ListFilesWithPrefix lists files within a given path that have a given prefix
|
// ListFilesWithPrefix lists files within a given path that have a given prefix
|
||||||
func ListFilesWithPrefix(path string, prefix string) []string {
|
func ListFilesWithPrefix(path string, prefix string) []string {
|
||||||
names, err := ioutil.ReadDir(path)
|
names, err := os.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
@@ -144,7 +143,7 @@ func ListFilesWithPrefix(path string, prefix string) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Mode().IsRegular() {
|
if f.Type().IsRegular() {
|
||||||
files = append(files, fmt.Sprintf("%s/%s", path, f.Name()))
|
files = append(files, fmt.Sprintf("%s/%s", path, f.Name()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"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")
|
return properties, errors.New("Specified property path is not a directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(pluginAppConfigRoot)
|
files, err := os.ReadDir(pluginAppConfigRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return properties, err
|
return properties, err
|
||||||
}
|
}
|
||||||
@@ -139,7 +138,7 @@ func PropertyGetDefault(pluginName, appName, property, defaultValue string) (val
|
|||||||
}
|
}
|
||||||
|
|
||||||
propertyPath := getPropertyPath(pluginName, appName, property)
|
propertyPath := getPropertyPath(pluginName, appName, property)
|
||||||
b, err := ioutil.ReadFile(propertyPath)
|
b, err := os.ReadFile(propertyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogWarn(fmt.Sprintf("Unable to read %s property %s.%s", pluginName, appName, property))
|
LogWarn(fmt.Sprintf("Unable to read %s property %s.%s", pluginName, appName, property))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -104,8 +104,8 @@ func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
|
|||||||
wE.Close()
|
wE.Close()
|
||||||
wO.Close()
|
wO.Close()
|
||||||
|
|
||||||
readStderr, _ := ioutil.ReadAll(rE)
|
readStderr, _ := io.ReadAll(rE)
|
||||||
readStdout, _ := ioutil.ReadAll(rO)
|
readStdout, _ := io.ReadAll(rO)
|
||||||
|
|
||||||
stderr := string(readStderr[:])
|
stderr := string(readStderr[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -29,12 +28,12 @@ func setupTests() (err error) {
|
|||||||
func setupTestApp() (err error) {
|
func setupTestApp() (err error) {
|
||||||
Expect(os.MkdirAll(testAppDir, 0766)).To(Succeed())
|
Expect(os.MkdirAll(testAppDir, 0766)).To(Succeed())
|
||||||
b := []byte("export testKey=TESTING\n")
|
b := []byte("export testKey=TESTING\n")
|
||||||
if err = ioutil.WriteFile(strings.Join([]string{testAppDir, "/ENV"}, ""), b, 0644); err != nil {
|
if err = os.WriteFile(strings.Join([]string{testAppDir, "/ENV"}, ""), b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b = []byte("export testKey=GLOBAL_TESTING\nexport globalKey=GLOBAL_VALUE")
|
b = []byte("export testKey=GLOBAL_TESTING\nexport globalKey=GLOBAL_VALUE")
|
||||||
if err = ioutil.WriteFile(globalConfigFile, b, 0644); err != nil {
|
if err = os.WriteFile(globalConfigFile, b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -179,7 +178,7 @@ func TestInvalidEnvOnDisk(t *testing.T) {
|
|||||||
|
|
||||||
appConfigFile := strings.Join([]string{testAppDir, "/ENV"}, "")
|
appConfigFile := strings.Join([]string{testAppDir, "/ENV"}, "")
|
||||||
b := []byte("export --invalid-key=TESTING\nexport valid_key=value\n")
|
b := []byte("export --invalid-key=TESTING\nexport valid_key=value\n")
|
||||||
if err := ioutil.WriteFile(appConfigFile, b, 0644); err != nil {
|
if err := os.WriteFile(appConfigFile, b, 0644); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +191,7 @@ func TestInvalidEnvOnDisk(t *testing.T) {
|
|||||||
Expect(value).To(Equal("value"))
|
Expect(value).To(Equal("value"))
|
||||||
|
|
||||||
//LoadAppEnv eliminates it from the file
|
//LoadAppEnv eliminates it from the file
|
||||||
content, err := ioutil.ReadFile(appConfigFile)
|
content, err := os.ReadFile(appConfigFile)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(strings.Contains(string(content), "--invalid-key")).To(BeFalse())
|
Expect(strings.Contains(string(content), "--invalid-key")).To(BeFalse())
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package cron
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
appjson "github.com/dokku/dokku/plugins/app-json"
|
appjson "github.com/dokku/dokku/plugins/app-json"
|
||||||
@@ -52,7 +52,7 @@ func FetchCronEntries(appName string) ([]TemplateCommand, error) {
|
|||||||
return commands, nil
|
return commands, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(appjsonPath)
|
b, err := os.ReadFile(appjsonPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return commands, fmt.Errorf("Cannot read app.json file for %s: %v", appName, err)
|
return commands, fmt.Errorf("Cannot read app.json file for %s: %v", appName, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package logs
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// TriggerDockerArgsProcessDeploy outputs the logs plugin docker options for an app
|
// TriggerDockerArgsProcessDeploy outputs the logs plugin docker options for an app
|
||||||
func TriggerDockerArgsProcessDeploy(appName string) error {
|
func TriggerDockerArgsProcessDeploy(appName string) error {
|
||||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
stdin, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package network
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// TriggerDockerArgsProcess outputs the network plugin docker options for an app
|
// TriggerDockerArgsProcess outputs the network plugin docker options for an app
|
||||||
func TriggerDockerArgsProcess(appName string) error {
|
func TriggerDockerArgsProcess(appName string) error {
|
||||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
stdin, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package registry
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// CommandLogin logs a user into the specified server
|
// CommandLogin logs a user into the specified server
|
||||||
func CommandLogin(server string, username string, password string, passwordStdin bool) error {
|
func CommandLogin(server string, username string, password string, passwordStdin bool) error {
|
||||||
if passwordStdin {
|
if passwordStdin {
|
||||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
stdin, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// TriggerDockerArgsProcessDeploy outputs the process-specific docker options
|
// TriggerDockerArgsProcessDeploy outputs the process-specific docker options
|
||||||
func TriggerDockerArgsProcessDeploy(appName string, processType string) error {
|
func TriggerDockerArgsProcessDeploy(appName string, processType string) error {
|
||||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
stdin, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package schedulerdockerlocal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -128,7 +127,7 @@ func writeCronEntries() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "WriteCronEntries"))
|
tmpFile, err := os.CreateTemp(os.TempDir(), fmt.Sprintf("dokku-%s-%s", common.MustGetEnv("DOKKU_PID"), "WriteCronEntries"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Cannot create temporary schedule file: %v", err)
|
return fmt.Errorf("Cannot create temporary schedule file: %v", err)
|
||||||
}
|
}
|
||||||
@@ -156,7 +155,7 @@ func getCronTemplate() (*template.Template, error) {
|
|||||||
t := template.New("cron")
|
t := template.New("cron")
|
||||||
|
|
||||||
templatePath := filepath.Join(common.MustGetEnv("PLUGIN_ENABLED_PATH"), "cron", "templates", "cron.tmpl")
|
templatePath := filepath.Join(common.MustGetEnv("PLUGIN_ENABLED_PATH"), "cron", "templates", "cron.tmpl")
|
||||||
b, err := ioutil.ReadFile(templatePath)
|
b, err := os.ReadFile(templatePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return t, fmt.Errorf("Cannot read template file: %v", err)
|
return t, fmt.Errorf("Cannot read template file: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user