@@ -127,3 +127,78 @@ func downloadPlugin(pluginInfo *plugin.Info, downloadInfo *resolver.PluginDownlo
127127 }
128128 return targetFile , nil
129129}
130+
131+ //gocyclo:ignore
132+ func downloadBatchPlugins (pluginInfos []* plugin.Info , downloadInfo * resolver.BatchPluginDownloadInfo , showProgress bool ) error {
133+ req , err := grab .NewRequest (PluginDir , downloadInfo .URL )
134+ if err != nil {
135+ return err
136+ }
137+ if downloadInfo .Checksum != "" {
138+ sum , decErr := hex .DecodeString (downloadInfo .Checksum )
139+ if decErr != nil {
140+ return fmt .Errorf ("could not decode checksum: %w" , decErr )
141+ }
142+ req .SetChecksum (sha256 .New (), sum , true )
143+ }
144+
145+ res := grab .DefaultClient .Do (req )
146+ if showProgress {
147+ showDownloadProgressBar ("batched-plugins" , res )
148+ }
149+ err = res .Err ()
150+ if err != nil {
151+ return err
152+ }
153+ defer os .Remove (res .Filename )
154+
155+ tgzFile , err := os .Open (res .Filename )
156+ if err != nil {
157+ return err
158+ }
159+ defer tgzFile .Close ()
160+
161+ gunzip , err := gzip .NewReader (tgzFile )
162+ if err != nil {
163+ return err
164+ }
165+ defer gunzip .Close ()
166+
167+ tarReader := tar .NewReader (gunzip )
168+ for {
169+ header , tarErr := tarReader .Next ()
170+ if errors .Is (tarErr , io .EOF ) {
171+ break
172+ }
173+ if tarErr != nil {
174+ return tarErr
175+ }
176+ if header .Typeflag != tar .TypeReg {
177+ continue
178+ }
179+
180+ outFileName := path .Join (PluginDir , header .Name )
181+ outDirName := path .Dir (outFileName )
182+ if err = os .MkdirAll (outDirName , 0o755 ); err != nil {
183+ return err
184+ }
185+
186+ outFile , oErr := os .OpenFile (outFileName , os .O_CREATE | os .O_WRONLY , 0o755 )
187+ if oErr != nil {
188+ return oErr
189+ }
190+ _ , cErr := io .Copy (outFile , tarReader )
191+ _ = outFile .Close ()
192+ if cErr != nil {
193+ return cErr
194+ }
195+
196+ for _ , pluginInfo := range pluginInfos {
197+ if strings .HasPrefix (path .Join (PluginDir , header .Name ), pluginInfo .PluginPath ) {
198+ pluginInfo .BinPath = outFileName
199+ }
200+ }
201+
202+ }
203+ return nil
204+ }
0 commit comments