optimizations
This commit is contained in:
parent
b3570772e7
commit
b937d62cc2
1 changed files with 25 additions and 8 deletions
33
main.go
33
main.go
|
@ -247,8 +247,16 @@ func contains(slice []string, item string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
func processAPK(filePath string) Package {
|
||||
func processAPK(filePath string,indexCache Index) Package {
|
||||
fmt.Printf("Processing APK: %s\n", filePath)
|
||||
for _, pkgs := range indexCache.Packages {
|
||||
for _, pkg := range pkgs {
|
||||
if pkg.ApkName == filePath {
|
||||
log.Printf("Warning: using %s metadata from cache",filePath)
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
enc := xml.NewEncoder(&buf)
|
||||
|
||||
|
@ -394,7 +402,7 @@ func getFilenameFromURL(urlStr string) (string, error) {
|
|||
|
||||
|
||||
// Function to handle downloading and processing APKs from a release
|
||||
func handleRelease(release Release) []Package {
|
||||
func handleRelease(release Release,indexCache Index) []Package {
|
||||
var packages []Package
|
||||
for _, asset := range release.Assets {
|
||||
if !isAPK(asset.BrowserDownloadURL) {
|
||||
|
@ -412,7 +420,7 @@ func handleRelease(release Release) []Package {
|
|||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
packageInfo := processAPK(filePath)
|
||||
packageInfo := processAPK(filePath,indexCache)
|
||||
packages = append(packages,packageInfo)
|
||||
}
|
||||
|
||||
|
@ -513,7 +521,7 @@ func signJarWithJarsigner(jarFile string, keystore string, password string, alia
|
|||
return err, string(output) // Возвращаем ошибку и вывод как строку
|
||||
}
|
||||
|
||||
func createAppFromReleases(releases []Release, repo string, index int) (App, []Package,error) {
|
||||
func createAppFromReleases(releases []Release, repo string, index int,indexCache Index) (App, []Package,error) {
|
||||
// Получаем информацию о репозитории
|
||||
repository, err := getRepositoryInfo(repo)
|
||||
if err != nil {
|
||||
|
@ -525,9 +533,9 @@ func createAppFromReleases(releases []Release, repo string, index int) (App, []P
|
|||
return App{}, []Package{}, nil
|
||||
}
|
||||
release := releases[index]
|
||||
packages := handleRelease(release)
|
||||
packages := handleRelease(release,indexCache)
|
||||
if len(packages) == 0 {
|
||||
return createAppFromReleases(releases,repo,index+1)
|
||||
return createAppFromReleases(releases,repo,index+1,indexCache)
|
||||
//return App{}, []Package{}, nil
|
||||
}
|
||||
app := App{
|
||||
|
@ -555,16 +563,25 @@ func createAppFromReleases(releases []Release, repo string, index int) (App, []P
|
|||
|
||||
func main() {
|
||||
var apps []App
|
||||
var indexCache Index
|
||||
var packages map[string][]Package
|
||||
packages = make(map[string][]Package)
|
||||
var config Config
|
||||
file, err := os.Open("config.toml")
|
||||
fileJson,errJson := os.Open("index-v1.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if errJson != nil {
|
||||
log.Printf("Error opening index cache so cache will not used: %s",errJson)
|
||||
indexCache = Index{}
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
defer fileJson.Close()
|
||||
// Parse the TOML file into the config struct
|
||||
if errJson := json.NewDecoder(fileJson).Decode(&indexCache); err != nil {
|
||||
log.Printf("Error decoding index cache so cache will not used: %s",errJson)
|
||||
}
|
||||
if _, err := toml.NewDecoder(file).Decode(&config); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -591,7 +608,7 @@ for _, source := range config.BinarySources {
|
|||
|
||||
var app App
|
||||
fmt.Println("Creating app object from repository info and apk")
|
||||
app,app_packages, err := createAppFromReleases(releases,repo,0)
|
||||
app,app_packages, err := createAppFromReleases(releases,repo,0,indexCache)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to create app from releases: ",err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue