From 49809b0a5969e7c8049001e123b73e6ed0dbded4 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Fri, 11 Aug 2017 14:05:06 -0700 Subject: [PATCH] check for namespaces/ dir before reading it Signed-off-by: Steve Kriss --- pkg/restore/restore.go | 9 +++++++++ pkg/restore/restore_test.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 18984c01a..cb6df7309 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -210,6 +210,15 @@ func (kr *kubernetesRestorer) restoreFromDir( // namespace-scoped namespacesPath := path.Join(dir, api.NamespaceScopedDir) + exists, err = kr.fileSystem.DirExists(namespacesPath) + if err != nil { + addArkError(&errors, err) + return warnings, errors + } + if !exists { + return warnings, errors + } + nses, err := kr.fileSystem.ReadDir(namespacesPath) if err != nil { addArkError(&errors, err) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index aeef65b5d..99860061f 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -91,6 +91,13 @@ func TestRestoreMethod(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{}}, expectedReadDirs: []string{"bak/cluster", "bak/namespaces"}, }, + { + name: "namespaces dir is not read & does not error if it does not exist", + fileSystem: newFakeFileSystem().WithDirectories("bak/cluster"), + baseDir: "bak", + restore: &api.Restore{Spec: api.RestoreSpec{}}, + expectedReadDirs: []string{"bak/cluster"}, + }, { name: "namespacesToRestore having * restores all namespaces", fileSystem: newFakeFileSystem().WithDirectories("bak/cluster", "bak/namespaces/a", "bak/namespaces/b", "bak/namespaces/c"),