@@ -111,11 +111,16 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
111111 if l := len (sumIndex ); l > 0 {
112112 log .Printf ("fetched %d asset shasums" , l )
113113 }
114- index := map [string ]Asset {}
114+
115+ var (
116+ candidates = map [string ]Asset {}
117+ index = map [string ]Asset {}
118+ foundLinuxAMD64 = false
119+ )
115120 for _ , ga := range ghas {
116121 url := ga .BrowserDownloadURL
117- //only binary containers are supported
118- //TODO deb,rpm etc
122+ // only binary containers are supported
123+ // TODO deb,rpm etc
119124 fext := getFileExt (url )
120125 if fext == "" && ga .Size > 1024 * 1024 {
121126 fext = ".bin" // +1MB binary
@@ -127,21 +132,38 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
127132 log .Printf ("fetched asset has unsupported file type: %s (ext '%s')" , ga .Name , fext )
128133 continue
129134 }
130- //match
135+ // match
131136 os := getOS (ga .Name )
132137 arch := getArch (ga .Name )
133- //windows not supported yet
138+ // windows not supported yet
134139 if os == "windows" {
135140 log .Printf ("fetched asset is for windows: %s" , ga .Name )
136- //TODO: powershell
141+ // TODO: powershell
137142 // EG: iwr https://deno.land/x/install/install.ps1 -useb | iex
138143 continue
139144 }
140- //unknown os, cant use
145+
146+ // stop guessing for linux/amd64 assets when the exact match is found
147+ if os == "linux" && arch == "amd64" {
148+ foundLinuxAMD64 = true
149+ }
150+ assumedLinuxAsset := false
151+ // unknown arch/os, the asset will be regarded as linux/amd64 if no other assets match
141152 if os == "" {
142- log .Printf ("fetched asset has unknown os: %s" , ga .Name )
143- continue
153+ assumedLinuxAsset = true
154+ if arch == "" || arch == "amd64" {
155+ if foundLinuxAMD64 {
156+ continue
157+ }
158+ }
144159 }
160+ if arch == "" {
161+ arch = "amd64"
162+ if os == "linux" {
163+ assumedLinuxAsset = true
164+ }
165+ }
166+
145167 // user selecting a particular asset?
146168 if q .Select != "" && ! strings .Contains (ga .Name , q .Select ) {
147169 log .Printf ("select excludes asset: %s" , ga .Name )
@@ -155,10 +177,26 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
155177 Type : fext ,
156178 SHA256 : sumIndex [ga .Name ],
157179 }
158- //there can only be 1 file for each OS/Arch
180+
159181 key := asset .Key ()
160- other , exists := index [key ]
161- if exists {
182+ // "linux/", "/amd64" will all be assumed as "linux/amd64"
183+ if assumedLinuxAsset {
184+ // "linux/" always win.
185+ if key == "linux/" {
186+ delete (candidates , "/amd64" )
187+ foundLinuxAMD64 = true
188+
189+ // If key "linux/" exist,
190+ // assets like "unknown-os-i386" would be ignored (stop guessing OS)
191+ } else if _ , exists := candidates ["linux/" ]; exists {
192+ continue
193+ }
194+ candidates [key ] = asset
195+ continue
196+ }
197+
198+ // there can only be 1 file for each OS/Arch
199+ if other , exists := index [key ]; exists {
162200 gnu := func (s string ) bool { return strings .Contains (s , "gnu" ) }
163201 musl := func (s string ) bool { return strings .Contains (s , "musl" ) }
164202 g2m := gnu (other .Name ) && ! musl (other .Name ) && ! gnu (asset .Name ) && musl (asset .Name )
@@ -169,6 +207,18 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
169207 }
170208 index [key ] = asset
171209 }
210+
211+ for _ , cAsset := range candidates {
212+ // "/loong64" will be assumed to be "linux/loong64"
213+ if cAsset .OS == "" {
214+ cAsset .OS = "linux"
215+ }
216+ indexKey := cAsset .Key ()
217+ // and will only be selected if the exact match failed
218+ if _ , exists := index [indexKey ]; ! exists {
219+ index [indexKey ] = cAsset
220+ }
221+ }
172222 if len (index ) == 0 {
173223 return release , nil , errors .New ("no downloads found for this release" )
174224 }
@@ -199,10 +249,12 @@ func (as ghAssets) getSumIndex() (map[string]string, error) {
199249 }
200250 resp , err := httpGet (url )
201251 if err != nil {
202- fmt .Println (err )
203252 return nil , err
204253 }
205254 defer resp .Body .Close ()
255+ if resp .StatusCode != 200 {
256+ return nil , fmt .Errorf ("sum file request returned status: %s" , resp .Status )
257+ }
206258 // take each line and insert into the index
207259 index := map [string ]string {}
208260 s := bufio .NewScanner (resp .Body )
@@ -248,18 +300,18 @@ type ghRelease struct {
248300 ID int `json:"id"`
249301 Login string `json:"login"`
250302 } `json:"author"`
251- Body string `json:"body"`
252- CreatedAt string `json:"created_at"`
253- Draft bool `json:"draft"`
254- HTMLURL string `json:"html_url"`
255- ID int `json:"id"`
256- Name interface {} `json:"name"`
257- Prerelease bool `json:"prerelease"`
258- PublishedAt string `json:"published_at"`
259- TagName string `json:"tag_name"`
260- TarballURL string `json:"tarball_url"`
261- TargetCommitish string `json:"target_commitish"`
262- UploadURL string `json:"upload_url"`
263- URL string `json:"url"`
264- ZipballURL string `json:"zipball_url"`
303+ Body string `json:"body"`
304+ CreatedAt string `json:"created_at"`
305+ Draft bool `json:"draft"`
306+ HTMLURL string `json:"html_url"`
307+ ID int `json:"id"`
308+ Name any `json:"name"`
309+ Prerelease bool `json:"prerelease"`
310+ PublishedAt string `json:"published_at"`
311+ TagName string `json:"tag_name"`
312+ TarballURL string `json:"tarball_url"`
313+ TargetCommitish string `json:"target_commitish"`
314+ UploadURL string `json:"upload_url"`
315+ URL string `json:"url"`
316+ ZipballURL string `json:"zipball_url"`
265317}
0 commit comments