internal/getproviders: SearchLocalDirectory can handle symlinks

Previously this was failing to treat symlinks to directories as unpacked
layout, because our file info was only an Lstat result, not a full Stat.

Now we'll resolve the symlink first, allowing us to handle a symlink to
a directory. That's important because our internal/providercache behavior
is to symlink from one cache to another where possible.
This commit is contained in:
Martin Atkins 2020-03-25 12:24:18 -07:00
parent ad15459468
commit eb25fe8b24
1 changed files with 9 additions and 0 deletions

View File

@ -68,6 +68,15 @@ func SearchLocalDirectory(baseDir string) (map[addrs.Provider]PackageMetaList, e
providerAddr = addrs.NewProvider(hostname, namespace, typeName)
}
// The "info" passed to our function is an Lstat result, so it might
// be referring to a symbolic link. We'll do a full "Stat" on it
// now to make sure we're making tests against the real underlying
// filesystem object below.
info, err = os.Stat(fullPath)
if err != nil {
return fmt.Errorf("failed to read metadata about %s: %s", fullPath, err)
}
switch len(parts) {
case 5: // Might be unpacked layout
if !info.IsDir() {