3 Commits
Author SHA1 Message Date
EnumDev 154f546b7f Fix installed size being wrong 2025-10-25 13:03:36 +03:00
EnumDev c4a0e9f860 Add 'keep' flag 2025-10-17 21:11:16 +03:00
EnumDev b9d7dfd9d0 Update databases only once after compiling split packages 2025-10-17 15:02:30 +03:00
2 changed files with 34 additions and 15 deletions
+7 -1
View File
@@ -20,6 +20,7 @@ import (
var compile = flag.BoolP("compile", "c", false, "Compile BPM source package")
var skipCheck = flag.BoolP("skip-checks", "s", false, "Skip 'check' function while compiling")
var keepCompilationFiles = flag.BoolP("keep", "k", false, "Keep compilation files after successful package compilation")
var installDepends = flag.BoolP("depends", "d", false, "Install package dependencies for compilation")
var installPackage = flag.BoolP("install", "i", false, "Install compiled BPM package after compilation finishes")
var moveToBinaryDir = flag.BoolP("move", "m", false, "Move output packages to the current repository's binary directory")
@@ -163,6 +164,9 @@ func compilePackage(archive string) {
if *skipCheck {
args = append(args, "-s")
}
if *keepCompilationFiles {
args = append(args, "-k")
}
if *installDepends {
args = append(args, "-d")
}
@@ -231,11 +235,13 @@ func compilePackage(archive string) {
os.Rename(line, newPath)
outputPkgs[pkgInfo.Name] = newPath
bpmutilsshared.UpdateDatabases(repo)
} else {
outputPkgs[pkgInfo.Name] = line
}
}
if repo := bpmutilsshared.GetRepository(); repo != "" && *moveToBinaryDir {
bpmutilsshared.UpdateDatabases(repo)
}
// Print out generated packages
for k, v := range outputPkgs {
+27 -14
View File
@@ -58,31 +58,44 @@ func GenerateDatabase(path string) error {
// Initialize database entry
entry := BPMDatabaseEntry{}
entry.DownloadSize = info.Size()
entry.InstalledSize = 0
entry.Filepath, err = filepath.Rel(path, packagePath)
if err != nil {
return err
}
// Get package installed size
cmd := exec.Command("tar", "-t", "-v", "-f", packagePath, "files.tar.gz")
output, err := cmd.Output()
if err == nil {
entry.InstalledSize, err = strconv.ParseInt(strings.Fields(string(output))[2], 10, 64)
if err != nil {
return err
}
} else if err.(*exec.ExitError).ExitCode() == 2 {
entry.InstalledSize = 0
} else {
return err
}
// Get package info
entry.PackageInfo, err = ReadPacakgeInfoFromTarball(packagePath)
if err != nil {
return err
}
// Get package installed size
if entry.PackageInfo.Type == "binary" {
cmd := exec.Command("tar", "xf", packagePath, "pkg.files", "-O")
output, err := cmd.Output()
if err != nil {
return err
}
for _, line := range strings.Split(string(output), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
stringEntry := strings.Split(line, " ")
if len(stringEntry) < 5 {
return fmt.Errorf("pkg.files is not formatted correctly")
}
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 10, 64)
if err != nil {
return err
}
entry.InstalledSize += size
}
}
// Add entry to database
if _, ok := database.Entries[entry.PackageInfo.Name]; ok {
return fmt.Errorf("package (%s) has already been added to the database", entry.PackageInfo.Name)