Skip to content

Commit

Permalink
internal/providercache: Fix bug when symlink fails
Browse files Browse the repository at this point in the history
When installing a provider which is already cached, we attempt to create
a symlink from the install directory targeting the cache. If symlinking
fails due to missing OS/filesystem support, we instead want to copy the
cached provider.

The fallback code to do this would always fail, due to a missing target
directory. This commit fixes that. I was unable to find a way to add
automated tests around this, but I have manually verified the fix on
Windows 8.1.
  • Loading branch information
alisdair committed Jul 23, 2020
1 parent 5734a0c commit 440543f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/providercache/package_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func installFromLocalDir(ctx context.Context, meta getproviders.PackageMeta, tar

parentDir := filepath.Dir(absNew)
err = os.MkdirAll(parentDir, 0755)
if err != nil && os.IsExist(err) {
if err != nil {
return nil, fmt.Errorf("failed to create parent directories leading to %s: %s", targetDir, err)
}

Expand All @@ -168,7 +168,12 @@ func installFromLocalDir(ctx context.Context, meta getproviders.PackageMeta, tar
}

// If we get down here then symlinking failed and we need a deep copy
// instead.
// instead. To make a copy, we first need to create the target directory,
// which would otherwise be a symlink.
err = os.Mkdir(absNew, 0755)
if err != nil && os.IsExist(err) {
return nil, fmt.Errorf("failed to create directory %s: %s", absNew, err)
}
err = copydir.CopyDir(absNew, absCurrent)
if err != nil {
return nil, fmt.Errorf("failed to either symlink or copy %s to %s: %s", absCurrent, absNew, err)
Expand Down

0 comments on commit 440543f

Please sign in to comment.