Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop deprecated io/ioutil #409

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/sha1"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -184,7 +183,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
}

// create tmp dir
tempDir, err := ioutil.TempDir("", bucket.Name)
tempDir, err := os.MkdirTemp("", bucket.Name)
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.BucketNotReady(bucket, sourcev1.StorageOperationFailedReason, err.Error()), err
Expand Down Expand Up @@ -368,7 +367,7 @@ func (r *BucketReconciler) checksum(root string) (string, error) {
if !info.Mode().IsRegular() {
return nil
}
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions controllers/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controllers

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestBucketReconciler_checksum(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
root, err := ioutil.TempDir("", "bucket-checksum-")
root, err := os.MkdirTemp("", "bucket-checksum-")
if err != nil {
t.Fatal(err)
}
Expand All @@ -76,7 +75,7 @@ func mockFile(root, path, content string) error {
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
panic(err)
}
if err := ioutil.WriteFile(filePath, []byte(content), 0644); err != nil {
if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
panic(err)
}
return nil
Expand Down
3 changes: 1 addition & 2 deletions controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -223,7 +222,7 @@ func (r *GitRepositoryReconciler) checkDependencies(repository sourcev1.GitRepos

func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sourcev1.GitRepository) (sourcev1.GitRepository, error) {
// create tmp dir for the Git clone
tmpGit, err := ioutil.TempDir("", repository.Name)
tmpGit, err := os.MkdirTemp("", repository.Name)
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.GitRepositoryNotReady(repository, sourcev1.StorageOperationFailedReason, err.Error()), err
Expand Down
7 changes: 3 additions & 4 deletions controllers/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -459,7 +458,7 @@ var _ = Describe("GitRepositoryReconciler", func() {

// this one is linked to a real directory, so that I can
// exec `git submodule add` later
tmp, err := ioutil.TempDir("", "flux-test")
tmp, err := os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp)

Expand Down Expand Up @@ -697,7 +696,7 @@ var _ = Describe("GitRepositoryReconciler", func() {
res, err := http.Get(got.Status.URL)
Expect(err).NotTo(HaveOccurred())
Expect(res.StatusCode).To(Equal(http.StatusOK))
tmp, err := ioutil.TempDir("", "flux-test")
tmp, err := os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp)
_, err = untar.Untar(res.Body, filepath.Join(tmp, "tar"))
Expand Down Expand Up @@ -743,7 +742,7 @@ var _ = Describe("GitRepositoryReconciler", func() {
res, err = http.Get(got.Status.URL)
Expect(err).NotTo(HaveOccurred())
Expect(res.StatusCode).To(Equal(http.StatusOK))
tmp, err = ioutil.TempDir("", "flux-test")
tmp, err = os.MkdirTemp("", "flux-test")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(tmp)
_, err = untar.Untar(res.Body, filepath.Join(tmp, "tar"))
Expand Down
13 changes: 6 additions & 7 deletions controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -331,7 +330,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}
b, err := ioutil.ReadAll(indexFile)
b, err := io.ReadAll(indexFile)
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
}
Expand Down Expand Up @@ -376,7 +375,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
}
tmpFile, err := ioutil.TempFile("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
tmpFile, err := os.CreateTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
}
Expand Down Expand Up @@ -448,7 +447,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
}

// Create temporary working directory
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
Expand Down Expand Up @@ -491,7 +490,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
artifact sourcev1.Artifact, chart sourcev1.HelmChart, force bool) (sourcev1.HelmChart, error) {
// Create temporary working directory
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", chart.Namespace, chart.Name))
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
Expand Down Expand Up @@ -554,7 +553,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}

valuesData, err := ioutil.ReadFile(srcPath)
valuesData, err := os.ReadFile(srcPath)
if err != nil {
err = fmt.Errorf("failed to read from values file '%s': %w", v, err)
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
Expand Down Expand Up @@ -659,7 +658,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.StorageOperationFailedReason, err.Error()), err
}
b, err := ioutil.ReadAll(indexFile)
b, err := io.ReadAll(indexFile)
if err != nil {
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
}
Expand Down
9 changes: 4 additions & 5 deletions controllers/helmchart_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -612,7 +611,7 @@ var _ = Describe("HelmChartReconciler", func() {
return nil
}

b, err := ioutil.ReadFile(p)
b, err := os.ReadFile(p)
if err != nil {
return err
}
Expand Down Expand Up @@ -872,14 +871,14 @@ var _ = Describe("HelmChartReconciler", func() {
helmChart, err := loader.LoadDir(chartDir)
Expect(err).NotTo(HaveOccurred())

chartPackagePath, err := ioutil.TempDir("", fmt.Sprintf("chartpackage-%s-%s", helmChart.Name(), randStringRunes(5)))
chartPackagePath, err := os.MkdirTemp("", fmt.Sprintf("chartpackage-%s-%s", helmChart.Name(), randStringRunes(5)))
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(chartPackagePath)

pkg, err := chartutil.Save(helmChart, chartPackagePath)
Expect(err).NotTo(HaveOccurred())

b, err := ioutil.ReadFile(pkg)
b, err := os.ReadFile(pkg)
Expect(err).NotTo(HaveOccurred())

tgz := filepath.Base(pkg)
Expand Down Expand Up @@ -1078,7 +1077,7 @@ var _ = Describe("HelmChartReconciler", func() {
return nil
}

b, err := ioutil.ReadFile(p)
b, err := os.ReadFile(p)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions controllers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
}

localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath))
tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil {
return err
}
Expand Down Expand Up @@ -272,7 +271,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
// If successful, it sets the checksum and last update time on the artifact.
func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, mode os.FileMode) (err error) {
localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath))
tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil {
return err
}
Expand Down Expand Up @@ -311,7 +310,7 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
// If successful, it sets the checksum and last update time on the artifact.
func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error) {
localPath := s.LocalPath(*artifact)
tf, err := ioutil.TempFile(filepath.Split(localPath))
tf, err := os.CreateTemp(filepath.Split(localPath))
if err != nil {
return err
}
Expand Down Expand Up @@ -357,7 +356,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
// CopyToPath copies the contents of the given artifact to the path.
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
// create a tmp directory to store artifact
tmp, err := ioutil.TempDir("", "flux-include")
tmp, err := os.MkdirTemp("", "flux-include")
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions controllers/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -34,7 +33,7 @@ import (
)

func createStoragePath() (string, error) {
return ioutil.TempDir("", "")
return os.MkdirTemp("", "")
}

func cleanupStoragePath(dir string) func() {
Expand All @@ -52,7 +51,7 @@ func TestStorageConstructor(t *testing.T) {
t.Fatal("nonexistent path was allowable in storage constructor")
}

f, err := ioutil.TempFile(dir, "")
f, err := os.CreateTemp(dir, "")
if err != nil {
t.Fatalf("while creating temporary file: %v", err)
}
Expand Down Expand Up @@ -124,7 +123,7 @@ func TestStorage_Archive(t *testing.T) {
os.RemoveAll(dir)
}
}()
dir, err = ioutil.TempDir("", "archive-test-files-")
dir, err = os.MkdirTemp("", "archive-test-files-")
if err != nil {
return
}
Expand Down Expand Up @@ -244,7 +243,7 @@ func TestStorage_Archive(t *testing.T) {

func TestStorageRemoveAllButCurrent(t *testing.T) {
t.Run("bad directory in archive", func(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 4 additions & 5 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controllers

import (
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -97,7 +96,7 @@ var _ = BeforeSuite(func(done Done) {

Expect(loadExampleKeys()).To(Succeed())

tmpStoragePath, err := ioutil.TempDir("", "source-controller-storage-")
tmpStoragePath, err := os.MkdirTemp("", "source-controller-storage-")
Expect(err).NotTo(HaveOccurred(), "failed to create tmp storage dir")

storage, err = NewStorage(tmpStoragePath, "localhost:5050", time.Second*30)
Expand Down Expand Up @@ -167,15 +166,15 @@ func init() {
}

func loadExampleKeys() (err error) {
examplePublicKey, err = ioutil.ReadFile("testdata/certs/server.pem")
examplePublicKey, err = os.ReadFile("testdata/certs/server.pem")
if err != nil {
return err
}
examplePrivateKey, err = ioutil.ReadFile("testdata/certs/server-key.pem")
examplePrivateKey, err = os.ReadFile("testdata/certs/server-key.pem")
if err != nil {
return err
}
exampleCA, err = ioutil.ReadFile("testdata/certs/ca.pem")
exampleCA, err = os.ReadFile("testdata/certs/ca.pem")
return err
}

Expand Down
3 changes: 1 addition & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -92,7 +91,7 @@ func CopyDir(src, dst string) error {
return fmt.Errorf("cannot mkdir %s: %w", dst, err)
}

entries, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return fmt.Errorf("cannot read directory %s: %w", dst, err)
}
Expand Down
Loading