From 85af77386cb777b1d3ebce9736e60228a84479b6 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 23 Apr 2020 18:12:01 -0700 Subject: [PATCH] internal/getproviders: PackageFilePathForPackage This is the equivalent of UnpackedDirectoryPathForPackage when working with the packed directory layout. It returns a path to a .zip file with a name that would be detected by SearchLocalDirectory as a PackageLocalArchive package. --- internal/getproviders/filesystem_search.go | 13 +++++++++++++ internal/getproviders/types.go | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/getproviders/filesystem_search.go b/internal/getproviders/filesystem_search.go index e3cd047b1..ed5a9e194 100644 --- a/internal/getproviders/filesystem_search.go +++ b/internal/getproviders/filesystem_search.go @@ -243,3 +243,16 @@ func UnpackedDirectoryPathForPackage(baseDir string, provider addrs.Provider, ve platform.String(), )) } + +// PackedFilePathForPackage is similar to +// PackageMeta.PackedFilePath but makes its decision based on +// individually-passed provider address, version, and target platform so that +// it can be used by callers outside this package that may have other +// types that represent package identifiers. +func PackedFilePathForPackage(baseDir string, provider addrs.Provider, version Version, platform Platform) string { + return filepath.ToSlash(filepath.Join( + baseDir, + provider.Hostname.ForDisplay(), provider.Namespace, provider.Type, + fmt.Sprintf("terraform-provider-%s_%s_%s.zip", provider.Type, version.String(), platform.String()), + )) +} diff --git a/internal/getproviders/types.go b/internal/getproviders/types.go index 4c485adb5..cc416a42c 100644 --- a/internal/getproviders/types.go +++ b/internal/getproviders/types.go @@ -230,6 +230,17 @@ func (m PackageMeta) UnpackedDirectoryPath(baseDir string) string { return UnpackedDirectoryPathForPackage(baseDir, m.Provider, m.Version, m.TargetPlatform) } +// PackedFilePath determines the path under the given base +// directory where SearchLocalDirectory or the FilesystemMirrorSource would +// expect to find packed copy (a .zip archive) of the receiving PackageMeta. +// +// The result always uses forward slashes as path separator, even on Windows, +// to produce a consistent result on all platforms. Windows accepts both +// direction of slash as long as each individual path string is self-consistent. +func (m PackageMeta) PackedFilePath(baseDir string) string { + return PackedFilePathForPackage(baseDir, m.Provider, m.Version, m.TargetPlatform) +} + // PackageLocation represents a location where a provider distribution package // can be obtained. A value of this type contains one of the following // concrete types: PackageLocalArchive, PackageLocalDir, or PackageHTTPURL.