Merge pull request #547 from ceh/issue-518

Fix issue 518
This commit is contained in:
Seth Vargo 2014-11-20 13:30:14 -05:00
commit 94e1eac051
2 changed files with 47 additions and 0 deletions

View File

@ -100,3 +100,45 @@ func TestInit_noArgs(t *testing.T) {
t.Fatalf("bad: \n%s", ui.OutputWriter.String()) t.Fatalf("bad: \n%s", ui.OutputWriter.String())
} }
} }
// https://github.com/hashicorp/terraform/issues/518
func TestInit_dstInSrc(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)
}
}

View File

@ -39,6 +39,11 @@ func copyDir(dst, src string) error {
// If we have a directory, make that subdirectory, then continue // If we have a directory, make that subdirectory, then continue
// the walk. // the walk.
if info.IsDir() { 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 { if err := os.MkdirAll(dstPath, 0755); err != nil {
return err return err
} }