MCPcopy Index your code
hub / github.com/version-fox/vfox / moveRemoteFile

Method moveRemoteFile

internal/sdk/sdk.go:278–314  ·  view source on GitHub ↗
(info *plugin.PreInstallPackageItem, targetPath string)

Source from the content-addressed store, hash-verified

276}
277
278func (b *impl) moveRemoteFile(info *plugin.PreInstallPackageItem, targetPath string) error {
279 u, err := url.Parse(info.Path)
280 label := info.Label()
281 if err != nil {
282 return err
283 }
284 filePath, err := b.Download(u, info.Headers)
285 if err != nil {
286 return fmt.Errorf("failed to download %s file, err:%w", label, err)
287 }
288 defer func() {
289 // del cache file
290 _ = os.Remove(filePath)
291 }()
292 checksum := info.Checksum()
293 pterm.Printf("Verifying checksum %s...\n", checksum.Value)
294 verify := checksum.Verify(filePath)
295 if !verify {
296 fmt.Printf("Checksum error, file: %s\n", filePath)
297 return errors.New("checksum error")
298 }
299 decompressor := util.NewDecompressor(filePath)
300 if decompressor == nil {
301 // If it is not a compressed file, move file to the corresponding sdk directory,
302 // and the rest be handled by the PostInstall function.
303 if err = util.MoveFiles(filePath, targetPath); err != nil {
304 return fmt.Errorf("failed to move file, err:%w", err)
305 }
306 return nil
307 }
308 pterm.Printf("Unpacking %s...\n", filePath)
309 err = decompressor.Decompress(targetPath)
310 if err != nil {
311 return fmt.Errorf("unpack failed, err:%w", err)
312 }
313 return nil
314}
315
316func (b *impl) runtimePathDirName(isMain bool, info *plugin.PreInstallPackageItem) string {
317 var name string

Callers 1

preInstallSdkMethod · 0.95

Calls 8

DownloadMethod · 0.95
DecompressMethod · 0.95
NewDecompressorFunction · 0.92
MoveFilesFunction · 0.92
VerifyMethod · 0.80
RemoveMethod · 0.65
LabelMethod · 0.45
ChecksumMethod · 0.45

Tested by

no test coverage detected