Skip to content

Commit

Permalink
(fix) replace deprecated ioutil references with stable versions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Lamarre <[email protected]>
  • Loading branch information
alexandreLamarre committed Feb 13, 2025
1 parent 7dcf955 commit 8287a7e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -644,7 +643,7 @@ func cleanCache(c *cli.Context) {
}

func parseScriptOptions() *options.ChartsScriptOptions {
configYaml, err := ioutil.ReadFile(ChartsScriptOptionsFile)
configYaml, err := os.ReadFile(ChartsScriptOptionsFile)
if err != nil {
logrus.Fatalf("Unable to find configuration file: %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/charts/crdchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -77,7 +76,7 @@ func AddCRDValidationToChart(fs billy.Filesystem, helmChartPathWithoutCRDs, helm
return nil
}
absPath := filesystem.GetAbsPath(fs, path)
yamlFile, err := ioutil.ReadFile(absPath)
yamlFile, err := os.ReadFile(absPath)
if err != nil {
return fmt.Errorf("unable to read file %s: %s", absPath, err)
}
Expand Down Expand Up @@ -133,7 +132,7 @@ func AddCRDValidationToChart(fs billy.Filesystem, helmChartPathWithoutCRDs, helm
validateInstallCRDsContents := fmt.Sprintf(ValidateInstallCRDContentsFmt, strings.Join(formattedCRDs, "\n"))
validateInstallCRDsDestpath := filepath.Join(helmChartPathWithoutCRDs, path.ChartValidateInstallCRDFile)
// Write to file
err = ioutil.WriteFile(filesystem.GetAbsPath(fs, validateInstallCRDsDestpath), []byte(validateInstallCRDsContents), os.ModePerm)
err = os.WriteFile(filesystem.GetAbsPath(fs, validateInstallCRDsDestpath), []byte(validateInstallCRDsContents), os.ModePerm)
if err != nil {
return fmt.Errorf("encountered error while writing into %s: %s", validateInstallCRDsDestpath, err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"compress/gzip"
"crypto/sha1"
"fmt"
"github.com/rancher/charts-build-scripts/pkg/util"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"sort"
"strings"

"github.com/rancher/charts-build-scripts/pkg/util"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -591,11 +591,11 @@ func CopyDir(fs billy.Filesystem, srcDir string, dstDir string) error {
if isDir {
return fs.MkdirAll(dstPath, os.ModePerm)
}
data, err := ioutil.ReadFile(GetAbsPath(fs, srcPath))
data, err := os.ReadFile(GetAbsPath(fs, srcPath))
if err != nil {
return err
}
return ioutil.WriteFile(GetAbsPath(fs, dstPath), data, os.ModePerm)
return os.WriteFile(GetAbsPath(fs, dstPath), data, os.ModePerm)
})
}

Expand All @@ -608,7 +608,7 @@ func MakeSubdirectoryRoot(fs billy.Filesystem, path, subdirectory string) error
if !exists {
return fmt.Errorf("subdirectory %s does not exist in path %s in filesystem %s", subdirectory, path, fs.Root())
}
absTempDir, err := ioutil.TempDir(fs.Root(), "make-subdirectory-root")
absTempDir, err := os.MkdirTemp(fs.Root(), "make-subdirectory-root")
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/options/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package options

import (
"fmt"
"io/ioutil"
"os"

"github.com/go-git/go-billy/v5"
Expand Down Expand Up @@ -105,7 +104,7 @@ func LoadPackageOptionsFromFile(fs billy.Filesystem, path string) (PackageOption
if !exists {
return packageOptions, fmt.Errorf("unable to load package options from file %s since it does not exist", filesystem.GetAbsPath(fs, path))
}
chartOptionsBytes, err := ioutil.ReadFile(filesystem.GetAbsPath(fs, path))
chartOptionsBytes, err := os.ReadFile(filesystem.GetAbsPath(fs, path))
if err != nil {
return packageOptions, err
}
Expand Down Expand Up @@ -146,7 +145,7 @@ func LoadChartOptionsFromFile(fs billy.Filesystem, path string) (ChartOptions, e
if !exists {
return chartOptions, fmt.Errorf("unable to load chart options from file %s since it does not exist", filesystem.GetAbsPath(fs, path))
}
chartOptionsBytes, err := ioutil.ReadFile(filesystem.GetAbsPath(fs, path))
chartOptionsBytes, err := os.ReadFile(filesystem.GetAbsPath(fs, path))
if err != nil {
return chartOptions, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/options/validate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package options

import (
"io/ioutil"
"os"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -78,7 +77,7 @@ func LoadReleaseOptionsFromFile(fs billy.Filesystem, path string) (ReleaseOption
// If release.yaml does not exist, return an empty ReleaseOptions
return releaseOptions, nil
}
releaseOptionsBytes, err := ioutil.ReadFile(filesystem.GetAbsPath(fs, path))
releaseOptionsBytes, err := os.ReadFile(filesystem.GetAbsPath(fs, path))
if err != nil {
return releaseOptions, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/regsync/generateconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -216,7 +215,7 @@ func decodeValuesFilesInTgz(tgzPath string) ([]map[interface{}]interface{}, erro

// decodeYAMLFile unmarshals the values into the target interface
func decodeYAMLFile(r io.Reader, target interface{}) error {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package repository

import (
"fmt"
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -118,7 +117,7 @@ func CreateInitialCommit(repo *git.Repository) error {
if err != nil {
return err
}
if err = ioutil.WriteFile(path.Join(repoPath, "README.md"), []byte{}, 0644); err != nil {
if err = os.WriteFile(path.Join(repoPath, "README.md"), []byte{}, 0644); err != nil {
return err
}
return CommitAll(repo, "Create initial commit")
Expand Down

0 comments on commit 8287a7e

Please sign in to comment.