internal/providercache: LinkFromOtherCache removes target, not source

This was incorrectly removing the _source_ entry prior to creating the
symlink, therefore ending up with a dangling symlink and no source file.

This wasn't obvious before because the test case for LinkFromOtherCache
was also incorrectly named and therefore wasn't running. Fixing the name
of that test made this problem apparent.

The TestLinkFromOtherCache test case now ends up seeing the final resolved
directory rather than the symlink target, because of upstream changes
to the internal/getproviders filesystem scanning logic to handle symlinks
properly.
This commit is contained in:
Martin Atkins 2020-03-25 12:26:36 -07:00
parent eb25fe8b24
commit 537c1bedcf
2 changed files with 4 additions and 9 deletions

View File

@ -78,7 +78,7 @@ func (d *Dir) LinkFromOtherCache(entry *CachedProvider) error {
d.metaCache = nil d.metaCache = nil
// Delete anything that's already present at this path first. // Delete anything that's already present at this path first.
err = os.RemoveAll(currentPath) err = os.RemoveAll(newPath)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove existing %s before linking it to %s: %s", currentPath, newPath, err) return fmt.Errorf("failed to remove existing %s before linking it to %s: %s", currentPath, newPath, err)
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform/internal/getproviders" "github.com/hashicorp/terraform/internal/getproviders"
) )
func LinkFromOtherCache(t *testing.T) { func TestLinkFromOtherCache(t *testing.T) {
srcDirPath := "testdata/cachedir" srcDirPath := "testdata/cachedir"
tmpDirPath, err := ioutil.TempDir("", "terraform-test-providercache") tmpDirPath, err := ioutil.TempDir("", "terraform-test-providercache")
if err != nil { if err != nil {
@ -82,13 +82,8 @@ func LinkFromOtherCache(t *testing.T) {
// still packed and thus not considered to be a cache member. // still packed and thus not considered to be a cache member.
Version: versions.MustParseVersion("2.0.0"), Version: versions.MustParseVersion("2.0.0"),
// These are still pointed into the testdata directory because PackageDir: tmpDirPath + "/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64",
// we created a symlink in our tmpDir. (This part of the test ExecutableFile: tmpDirPath + "/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64/terraform-provider-null.exe",
// is expected to fail if the temporary directory is on a
// filesystem that cannot support symlinks, in which case
// we should see the temporary directory paths here instead.)
PackageDir: "testdata/cachedir/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64",
ExecutableFile: "testdata/cachedir/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64/terraform-provider-null.exe",
}, },
}, },
} }