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:
parent
eb25fe8b24
commit
537c1bedcf
|
@ -78,7 +78,7 @@ func (d *Dir) LinkFromOtherCache(entry *CachedProvider) error {
|
|||
d.metaCache = nil
|
||||
|
||||
// Delete anything that's already present at this path first.
|
||||
err = os.RemoveAll(currentPath)
|
||||
err = os.RemoveAll(newPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove existing %s before linking it to %s: %s", currentPath, newPath, err)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/hashicorp/terraform/internal/getproviders"
|
||||
)
|
||||
|
||||
func LinkFromOtherCache(t *testing.T) {
|
||||
func TestLinkFromOtherCache(t *testing.T) {
|
||||
srcDirPath := "testdata/cachedir"
|
||||
tmpDirPath, err := ioutil.TempDir("", "terraform-test-providercache")
|
||||
if err != nil {
|
||||
|
@ -82,13 +82,8 @@ func LinkFromOtherCache(t *testing.T) {
|
|||
// still packed and thus not considered to be a cache member.
|
||||
Version: versions.MustParseVersion("2.0.0"),
|
||||
|
||||
// These are still pointed into the testdata directory because
|
||||
// we created a symlink in our tmpDir. (This part of the test
|
||||
// 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",
|
||||
PackageDir: tmpDirPath + "/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64",
|
||||
ExecutableFile: tmpDirPath + "/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64/terraform-provider-null.exe",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue