Add package installation and last update dates

This commit is contained in:
2026-02-03 21:25:33 +02:00
parent ba0d288e45
commit b37360ed82
3 changed files with 75 additions and 4 deletions
+31 -2
View File
@@ -7,6 +7,8 @@ import (
"slices"
"strconv"
"strings"
"gopkg.in/yaml.v3"
)
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo)
@@ -144,10 +146,12 @@ func GetPackage(pkg, rootDir string) *BPMPackage {
}
files := getPackageFiles(pkgInfo.Name, rootDir)
localInfo := getPackageLocalInfo(pkgInfo.Name, rootDir)
return &BPMPackage{
PkgInfo: pkgInfo,
PkgFiles: files,
PkgInfo: pkgInfo,
PkgFiles: files,
LocalInfo: localInfo,
}
}
@@ -234,3 +238,28 @@ func getPackageFiles(pkg, rootDir string) []*PackageFileEntry {
return pkgFiles
}
func getPackageLocalInfo(pkg, rootDir string) PackageLocalInfo {
localInfo := PackageLocalInfo{}
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
pkgDir := path.Join(installedDir, pkg)
files := path.Join(pkgDir, "local")
if _, err := os.Stat(files); os.IsNotExist(err) {
return localInfo
}
file, err := os.Open(files)
if err != nil {
return localInfo
}
defer file.Close()
err = yaml.NewDecoder(file).Decode(&localInfo)
if err != nil {
return localInfo
}
return localInfo
}
+27 -2
View File
@@ -16,13 +16,15 @@ import (
"strconv"
"strings"
"syscall"
"time"
"gopkg.in/yaml.v3"
)
type BPMPackage struct {
PkgInfo *PackageInfo
PkgFiles []*PackageFileEntry
PkgInfo *PackageInfo
PkgFiles []*PackageFileEntry
LocalInfo PackageLocalInfo
}
type PackageInfo struct {
@@ -75,6 +77,11 @@ type PackageFileEntry struct {
SizeInBytes int64
}
type PackageLocalInfo struct {
InstalledOn int64 `yaml:"installed_on"`
LastUpdatedOn int64 `yaml:"last_updated_on"`
}
func (pkg *BPMPackage) GetInstalledSize() int64 {
var totalSize int64 = 0
for _, entry := range pkg.PkgFiles {
@@ -979,6 +986,24 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
return err
}
// Write local package information
localInfo := getPackageLocalInfo(bpmpkg.PkgInfo.Name, rootDir)
if !packageInstalled {
localInfo.InstalledOn = time.Now().Unix()
}
localInfo.LastUpdatedOn = time.Now().Unix()
localFile, err := os.OpenFile(path.Join(pkgDir, "local"), os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
defer localFile.Close()
err = yaml.NewEncoder(localFile).Encode(localInfo)
if err != nil {
return err
}
// Save remove package scripts
packageScripts, err := ReadPackageScripts(filename)
if err != nil {