From 795dc262149170f02b32075bf78efbc2ade183cd Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 5 Jul 2018 15:46:17 -0700 Subject: [PATCH] replace pkg/restore's osFileSystem with pkg/util/filesystem's Signed-off-by: Steve Kriss --- pkg/restore/file_system.go | 75 -------------------------------------- pkg/restore/restore.go | 8 ++-- 2 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 pkg/restore/file_system.go diff --git a/pkg/restore/file_system.go b/pkg/restore/file_system.go deleted file mode 100644 index b4715604a..000000000 --- a/pkg/restore/file_system.go +++ /dev/null @@ -1,75 +0,0 @@ -/* -Copyright 2017 the Heptio Ark contributors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package restore - -import ( - "io" - "io/ioutil" - "os" -) - -// FileSystem defines methods for interacting with an -// underlying file system. -type FileSystem interface { - TempDir(dir, prefix string) (string, error) - MkdirAll(path string, perm os.FileMode) error - Create(name string) (io.WriteCloser, error) - RemoveAll(path string) error - ReadDir(dirname string) ([]os.FileInfo, error) - ReadFile(filename string) ([]byte, error) - DirExists(path string) (bool, error) -} - -var _ FileSystem = &osFileSystem{} - -type osFileSystem struct { -} - -func (fs *osFileSystem) TempDir(dir, prefix string) (string, error) { - return ioutil.TempDir(dir, prefix) -} - -func (fs *osFileSystem) MkdirAll(path string, perm os.FileMode) error { - return os.MkdirAll(path, perm) -} - -func (fs *osFileSystem) Create(name string) (io.WriteCloser, error) { - return os.Create(name) -} - -func (fs *osFileSystem) RemoveAll(path string) error { - return os.RemoveAll(path) -} - -func (fs *osFileSystem) ReadDir(dirname string) ([]os.FileInfo, error) { - return ioutil.ReadDir(dirname) -} - -func (fs *osFileSystem) ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) -} - -func (fs *osFileSystem) DirExists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return false, err -} diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 22d404438..39e2992d0 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -55,6 +55,7 @@ import ( "github.com/heptio/ark/pkg/restic" "github.com/heptio/ark/pkg/util/boolptr" "github.com/heptio/ark/pkg/util/collections" + "github.com/heptio/ark/pkg/util/filesystem" "github.com/heptio/ark/pkg/util/kube" "github.com/heptio/ark/pkg/util/logging" arksync "github.com/heptio/ark/pkg/util/sync" @@ -80,7 +81,7 @@ type kubernetesRestorer struct { resticRestorerFactory restic.RestorerFactory resticTimeout time.Duration resourcePriorities []string - fileSystem FileSystem + fileSystem filesystem.Interface logger logrus.FieldLogger } @@ -165,8 +166,9 @@ func NewKubernetesRestorer( resticRestorerFactory: resticRestorerFactory, resticTimeout: resticTimeout, resourcePriorities: resourcePriorities, - fileSystem: &osFileSystem{}, logger: logger, + + fileSystem: filesystem.NewFileSystem(), }, nil } @@ -326,7 +328,7 @@ type context struct { selector labels.Selector logger logrus.FieldLogger dynamicFactory client.DynamicFactory - fileSystem FileSystem + fileSystem filesystem.Interface namespaceClient corev1.NamespaceInterface actions []resolvedAction snapshotService cloudprovider.SnapshotService