From eb25fe8b2444014f4b203fe9dee3d97b99030486 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 25 Mar 2020 12:24:18 -0700 Subject: [PATCH] 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. --- internal/getproviders/filesystem_search.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/getproviders/filesystem_search.go b/internal/getproviders/filesystem_search.go index 9c8dd59e10..23a7d3ce7c 100644 --- a/internal/getproviders/filesystem_search.go +++ b/internal/getproviders/filesystem_search.go @@ -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() {