MCPcopy Create free account
hub / github.com/Code-Hex/pget / Run

Method Run

pget.go:41–88  ·  view source on GitHub ↗

Run execute methods in pget package

(ctx context.Context, version string, args []string)

Source from the content-addressed store, hash-verified

39
40// Run execute methods in pget package
41func (pget *Pget) Run(ctx context.Context, version string, args []string) error {
42 if err := pget.Ready(version, args); err != nil {
43 return errTop(err)
44 }
45
46 // TODO(codehex): calc maxIdleConnsPerHost
47 client := newDownloadClient(16)
48
49 target, err := Check(ctx, &CheckConfig{
50 URLs: pget.URLs,
51 Timeout: time.Duration(pget.timeout) * time.Second,
52 Client: client,
53 })
54 if err != nil {
55 return err
56 }
57
58 filename := target.Filename
59
60 var dir string
61 if pget.Output != "" {
62 fi, err := os.Stat(pget.Output)
63 if err == nil && fi.IsDir() {
64 dir = pget.Output
65 } else {
66 dir, filename = filepath.Split(pget.Output)
67 if dir != "" {
68 if err := os.MkdirAll(dir, 0755); err != nil {
69 return errors.Wrapf(err, "failed to create diretory at %s", dir)
70 }
71 }
72 }
73 }
74
75 opts := []DownloadOption{
76 WithUserAgent(pget.useragent, version),
77 WithReferer(pget.referer),
78 }
79
80 return Download(ctx, &DownloadConfig{
81 Filename: filename,
82 Dirname: dir,
83 ContentLength: target.ContentLength,
84 Procs: pget.Procs,
85 URLs: target.URLs,
86 Client: client,
87 }, opts...)
88}
89
90const (
91 warningNumConnection = 4

Callers 5

TestParts_of_readyFunction · 0.80
TestMainFunction · 0.80
TestPgetFunction · 0.80
TestRunResumeFunction · 0.80
mainFunction · 0.80

Calls 7

ReadyMethod · 0.95
errTopFunction · 0.85
newDownloadClientFunction · 0.85
CheckFunction · 0.85
WithUserAgentFunction · 0.85
WithRefererFunction · 0.85
DownloadFunction · 0.85

Tested by 4

TestParts_of_readyFunction · 0.64
TestMainFunction · 0.64
TestPgetFunction · 0.64
TestRunResumeFunction · 0.64