From 82e4bab178171490cd71983e3c42b0558967c996 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Tue, 4 Nov 2014 21:19:39 +0100 Subject: [PATCH 1/3] command/init: test for issue 518 --- command/init_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/command/init_test.go b/command/init_test.go index 2db54b047..1321fc089 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -100,3 +100,45 @@ func TestInit_noArgs(t *testing.T) { t.Fatalf("bad: \n%s", ui.OutputWriter.String()) } } + +// https://github.com/hashicorp/terraform/issues/518 +func TestIssue518(t *testing.T) { + dir := tempDir(t) + if err := os.MkdirAll(dir, 0755); err != nil { + t.Fatalf("err: %s", err) + } + + // Change to the temporary directory + cwd, err := os.Getwd() + if err != nil { + t.Fatalf("err: %s", err) + } + if err := os.Chdir(dir); err != nil { + t.Fatalf("err: %s", err) + } + defer os.Chdir(cwd) + + if _, err := os.Create("issue518.tf"); err != nil { + t.Fatalf("err: %s", err) + } + + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{ + ".", + "foo", + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } + + if _, err := os.Stat(filepath.Join(dir, "foo", "issue518.tf")); err != nil { + t.Fatalf("err: %s", err) + } +} From a76290f27855c82273a28833e7ae49dfbbd6bcc1 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Tue, 4 Nov 2014 21:27:12 +0100 Subject: [PATCH 2/3] config/module: don't walk dst when dst is in src Fixes #518 --- config/module/copy_dir.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/module/copy_dir.go b/config/module/copy_dir.go index a6628d1d7..f2ae63b77 100644 --- a/config/module/copy_dir.go +++ b/config/module/copy_dir.go @@ -39,6 +39,11 @@ func copyDir(dst, src string) error { // If we have a directory, make that subdirectory, then continue // the walk. if info.IsDir() { + if path == filepath.Join(src, dst) { + // dst is in src; don't walk it. + return nil + } + if err := os.MkdirAll(dstPath, 0755); err != nil { return err } From 31dd7d8391c6e19b9016a630fe3119de49fed5bc Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Thu, 20 Nov 2014 19:17:04 +0100 Subject: [PATCH 3/3] command/init: use a more semantic name to identiy the test routine for issue 518 --- command/init_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/init_test.go b/command/init_test.go index 1321fc089..ebd05e0f2 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -102,7 +102,7 @@ func TestInit_noArgs(t *testing.T) { } // https://github.com/hashicorp/terraform/issues/518 -func TestIssue518(t *testing.T) { +func TestInit_dstInSrc(t *testing.T) { dir := tempDir(t) if err := os.MkdirAll(dir, 0755); err != nil { t.Fatalf("err: %s", err)