From b37360ed827784ba0fac47188c3b6c885dc6ea08 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Tue, 3 Feb 2026 21:25:33 +0200 Subject: [PATCH] Add package installation and last update dates --- src/bpm/main.go | 17 ++++++++++++++++ src/bpmlib/installed_packages.go | 33 ++++++++++++++++++++++++++++++-- src/bpmlib/packages.go | 29 ++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/bpm/main.go b/src/bpm/main.go index c38fba4..7719e22 100644 --- a/src/bpm/main.go +++ b/src/bpm/main.go @@ -13,6 +13,7 @@ import ( "slices" "sort" "strings" + "time" "github.com/EnumeratedDev/bpm/src/bpmlib" @@ -270,6 +271,14 @@ func showPackageInfo() { fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(bpmpkg.GetInstalledSize())) } } + + if bpmlib.IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) { + format := "02/01/2006 15:04" + installedOnDate := time.Unix(bpmpkg.LocalInfo.InstalledOn, 0).Format(format) + lastUpdatedOn := time.Unix(bpmpkg.LocalInfo.LastUpdatedOn, 0).Format(format) + fmt.Printf("Installed on: %s\n", installedOnDate) + fmt.Printf("Last updated on: %s\n", lastUpdatedOn) + } } } @@ -420,6 +429,14 @@ func showPackageList() { fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(pkg.installedSize)) } } + + localInfo := bpmlib.GetPackage(pkg.pkgInfo.Name, rootDir).LocalInfo + format := "02/01/2006 15:04" + installedOnDate := time.Unix(localInfo.InstalledOn, 0).Format(format) + lastUpdatedOn := time.Unix(localInfo.LastUpdatedOn, 0).Format(format) + fmt.Printf("Installed on: %s\n", installedOnDate) + fmt.Printf("Last updated on: %s\n", lastUpdatedOn) + } } } diff --git a/src/bpmlib/installed_packages.go b/src/bpmlib/installed_packages.go index bac60e3..b616508 100644 --- a/src/bpmlib/installed_packages.go +++ b/src/bpmlib/installed_packages.go @@ -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 +} diff --git a/src/bpmlib/packages.go b/src/bpmlib/packages.go index 5d0e5a4..ae81dd6 100644 --- a/src/bpmlib/packages.go +++ b/src/bpmlib/packages.go @@ -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 {