Skip to content

Commit 5589975

Browse files
committed
enhance asset handling by determining binary file types based on OS/Arch patterns; prefer larger static builds over dynamic ones; add size attribute to Asset struct
1 parent a9da2f8 commit 5589975

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

handler/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
180180

181181
type Asset struct {
182182
Name, OS, Arch, URL, Type, SHA256 string
183+
Size int
183184
}
184185

185186
func (a Asset) Key() string {

handler/handler_execute.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
121121
// only binary containers are supported
122122
// TODO deb,rpm etc
123123
fext := getFileExt(url)
124-
if fext == "" && ga.Size > 1024*1024 {
125-
fext = ".bin" // +1MB binary
124+
if fext == "" {
125+
// Check if this looks like a binary by checking for OS and Arch patterns
126+
// This handles assets like "joker_darwin_amd64" without extension
127+
if getOS(ga.Name) != "" && getArch(ga.Name) != "" && ga.Size > 1024 {
128+
fext = ".bin" // Likely a binary if it has OS/Arch in name and > 1KB
129+
}
126130
}
127131
switch fext {
128132
case ".bin", ".zip", ".tar.bz", ".tar.bz2", ".tar.xz", ".txz", ".bz2", ".gz", ".tar.gz", ".tgz":
@@ -175,6 +179,7 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
175179
URL: url,
176180
Type: fext,
177181
SHA256: sumIndex[ga.Name],
182+
Size: ga.Size,
178183
}
179184

180185
key := asset.Key()
@@ -201,7 +206,28 @@ func (h *Handler) getAssetsNoCache(q Query) (string, Assets, error) {
201206
g2m := gnu(other.Name) && !musl(other.Name) && !gnu(asset.Name) && musl(asset.Name)
202207
// prefer musl over glib for portability, override with select=gnu
203208
if !g2m {
204-
continue
209+
// If both are gnu or both are not gnu/musl, prefer the larger file (usually static build)
210+
// This handles cases like joker_linux_amd64 (497KB static) vs joker_linux_amd64_gnu (39KB dynamic)
211+
if (gnu(other.Name) == gnu(asset.Name)) && (musl(other.Name) == musl(asset.Name)) {
212+
if ga.Size > other.Size {
213+
log.Printf("preferring larger asset %s (%d bytes) over %s (%d bytes) for %s",
214+
ga.Name, ga.Size, other.Name, other.Size, key)
215+
} else {
216+
log.Printf("skipping smaller asset %s (%d bytes), keeping %s (%d bytes) for %s",
217+
ga.Name, ga.Size, other.Name, other.Size, key)
218+
continue
219+
}
220+
} else {
221+
// Different gnu/musl status, prefer non-gnu (static) over gnu (dynamic)
222+
if !gnu(other.Name) && gnu(asset.Name) {
223+
log.Printf("skipping gnu asset %s, preferring static build %s for %s",
224+
ga.Name, other.Name, key)
225+
} else if gnu(other.Name) && !gnu(asset.Name) {
226+
log.Printf("replacing gnu asset %s with static build %s for %s",
227+
other.Name, ga.Name, key)
228+
}
229+
continue
230+
}
205231
}
206232
}
207233
index[key] = asset

0 commit comments

Comments
 (0)