From 54282e3e8c9bbb022325a6baf44367d72d485bed Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 21 Jun 2018 14:07:59 -0700 Subject: [PATCH] Fix bug in snapshotting --- pkg/snapshot/snapshot_test.go | 2 +- pkg/util/command_util.go | 2 +- pkg/util/fs_util.go | 4 ++-- pkg/util/fs_util_test.go | 9 ++++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 7cee2ad11..f8f3c0161 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -149,7 +149,7 @@ func TestSnapshotFiles(t *testing.T) { if err != nil { t.Fatal(err) } - expectedFiles := []string{"/tmp", filepath.Join(testDir, "foo")} + expectedFiles := []string{"/", "/tmp", filepath.Join(testDir, "foo")} // Check contents of the snapshot, make sure contents is equivalent to snapshotFiles reader := bytes.NewReader(contents) diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 8fcefca0d..8d4bb3715 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -69,7 +69,7 @@ func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) return "", err } fp = filepath.Clean(fp) - if IsDestDir(value) { + if IsDestDir(value) && !IsDestDir(fp) { fp = fp + "/" } return fp, nil diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 7d8b6b456..825009d7f 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -336,12 +336,12 @@ func Files(root string) ([]string, error) { } // ParentDirectories returns a list of paths to all parent directories -// Ex. /some/temp/dir -> [/some, /some/temp, /some/temp/dir] +// Ex. /some/temp/dir -> [/, /some, /some/temp, /some/temp/dir] func ParentDirectories(path string) []string { path = filepath.Clean(path) dirs := strings.Split(path, "/") dirPath := constants.RootDir - var paths []string + paths := []string{constants.RootDir} for index, dir := range dirs { if dir == "" || index == (len(dirs)-1) { continue diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index 0feefd0eb..a9c871632 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -142,14 +142,17 @@ func Test_ParentDirectories(t *testing.T) { name: "regular path", path: "/path/to/dir", expected: []string{ + "/", "/path", "/path/to", }, }, { - name: "current directory", - path: ".", - expected: nil, + name: "current directory", + path: ".", + expected: []string{ + "/", + }, }, }