diff --git a/get_file_test.go b/get_file_test.go index 94ab3c1c1..221b94789 100644 --- a/get_file_test.go +++ b/get_file_test.go @@ -35,6 +35,32 @@ func TestFileGetter(t *testing.T) { } } +func TestFileGetterCopy(t *testing.T) { + g := new(FileGetter) + g.Copy = true + dst := tempDir(t) + + // With a dir that doesn't exist + if err := g.Get(dst, testModuleURL("basic")); err != nil { + t.Fatalf("err: %s", err) + } + + // Verify the destination folder is a symlink + fi, err := os.Lstat(dst) + if err != nil { + t.Fatalf("err: %s", err) + } + if fi.Mode()&os.ModeSymlink != 0 { + t.Fatal("destination is a symlink") + } + + // Verify the main file exists + mainPath := filepath.Join(dst, "main.tf") + if _, err := os.Stat(mainPath); err != nil { + t.Fatalf("err: %s", err) + } +} + func TestFileGetter_sourceFile(t *testing.T) { g := new(FileGetter) dst := tempDir(t) diff --git a/get_file_unix.go b/get_file_unix.go index 40ebc5af2..2937af061 100644 --- a/get_file_unix.go +++ b/get_file_unix.go @@ -45,7 +45,11 @@ func (g *FileGetter) Get(dst string, u *url.URL) error { return err } - return os.Symlink(path, dst) + if !g.Copy { + return os.Symlink(path, dst) + } + + return copyDir(g.Context(), dst, path, false, g.client.umask()) } func (g *FileGetter) GetFile(dst string, u *url.URL) error {