-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlistBinaries.go
69 lines (58 loc) · 1.8 KB
/
listBinaries.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// listBinaries.go // This file implements the listBinaries function //>
package main
import (
"path/filepath"
"strings"
)
// Excluded file types and file names that shall not appear in Lists nor in Search Results
var excludedFileTypes = []string{
".7z", ".bz2", ".json", ".gz", ".xz", ".md",
".txt", ".tar", ".zip", ".cfg", ".dir",
".test", //".appimage"
}
var excludedFileNames = []string{
"TEST", "LICENSE", "experimentalBinaries_dir", "bundles_dir",
"blobs_dir", "robotstxt", "bdl.sh",
"uroot", "uroot-busybox", "gobusybox",
"sysinfo-collector", "neofetch", "firefox.appimage",
"firefox-esr.appimage", "firefox-dev.appimage",
"firefox-nightly.appimage",
}
// listBinaries fetches and lists binary names from the given metadata URLs.
func listBinaries(metadata map[string]interface{}) ([]string, error) {
var allBinaries []string
// Iterate over all sections in the metadata
for _, section := range metadata {
binaries, ok := section.([]interface{})
if !ok {
continue
}
for _, item := range binaries {
binMap, ok := item.(map[string]interface{})
if !ok {
continue
}
realName, _ := binMap["pkg"].(string)
if realName != "" {
allBinaries = append(allBinaries, realName)
}
}
}
// Filter out excluded file types and file RealNames
filteredBinaries := filterBinaries(allBinaries)
// Return unique binaries
return removeDuplicates(filteredBinaries), nil
}
// filterBinaries filters the list of binaries based on exclusions.
func filterBinaries(binaries []string) []string {
var filtered []string
for _, binary := range binaries {
ext := strings.ToLower(filepath.Ext(binary))
base := filepath.Base(binary)
// Check for exclusions
if !contains(excludedFileTypes, ext) && !contains(excludedFileNames, base) {
filtered = append(filtered, binary)
}
}
return filtered
}