@@ -110,17 +110,33 @@ func (c *PackageCommand) Run(args []string) int {
110110 services := disco .New ()
111111 services .SetUserAgent (httpclient .TerraformUserAgent (version .String ()))
112112 var sources []getproviders.MultiSourceSelector
113- sources = append (sources , getproviders.MultiSourceSelector {
114- Source : getproviders .NewMemoizeSource (getproviders .NewRegistrySource (services )),
115- })
116- // if the pluginDir exists, include it as a potential source
113+
114+ // Find any local providers first so we can exclude these from the registry
115+ // install. We'll just silently ignore any errors and assume it would fail
116+ // real installation later too.
117+ var directExcluded getproviders.MultiSourceMatchingPatterns
117118 if absPluginDir , err := filepath .Abs (pluginDir ); err == nil {
118119 if _ , err := os .Stat (absPluginDir ); err == nil {
120+ localSource := getproviders .NewFilesystemMirrorSource (absPluginDir )
121+ if available , err := localSource .AllAvailablePackages (); err == nil {
122+ for found := range available {
123+ directExcluded = append (directExcluded , found )
124+ }
125+ }
119126 sources = append (sources , getproviders.MultiSourceSelector {
120- Source : getproviders . NewFilesystemMirrorSource ( absPluginDir ) ,
127+ Source : localSource ,
121128 })
122129 }
123130 }
131+
132+ c .ui .Warn (fmt .Sprintf ("excluding %#v" , directExcluded ))
133+
134+ // Add the registry source, minus any providers found in the local pluginDir.
135+ sources = append (sources , getproviders.MultiSourceSelector {
136+ Source : getproviders .NewMemoizeSource (getproviders .NewRegistrySource (services )),
137+ Exclude : directExcluded ,
138+ })
139+
124140 installer := providercache .NewInstaller (installdir , getproviders .MultiSource (sources ))
125141
126142 err = c .ensureProviderVersions (installer , reqs )
@@ -162,21 +178,17 @@ func (c *PackageCommand) Run(args []string) int {
162178 if err != nil {
163179 return err
164180 }
165- if info .IsDir () {
166- return nil
181+ // maybe symlinks
182+ linkPath , err := filepath .EvalSymlinks (path )
183+ if err != nil {
184+ return err
167185 }
168- if info .Mode ()& os .ModeSymlink == os .ModeSymlink {
169- linkPath , err := filepath .EvalSymlinks (path )
170- if err != nil {
171- return err
172- }
173- linkInfo , err := os .Stat (linkPath )
174- if err != nil {
175- return err
176- }
177- if linkInfo .IsDir () {
178- return nil
179- }
186+ linkInfo , err := os .Stat (linkPath )
187+ if err != nil {
188+ return err
189+ }
190+ if linkInfo .IsDir () {
191+ return nil
180192 }
181193
182194 fn := info .Name ()
0 commit comments