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
+17
View File
@@ -13,6 +13,7 @@ import (
"slices" "slices"
"sort" "sort"
"strings" "strings"
"time"
"github.com/EnumeratedDev/bpm/src/bpmlib" "github.com/EnumeratedDev/bpm/src/bpmlib"
@@ -270,6 +271,14 @@ func showPackageInfo() {
fmt.Printf("Installed size: %s\n", bpmlib.BytesToHumanReadable(bpmpkg.GetInstalledSize())) 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)) 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)
} }
} }
} }
+31 -2
View File
@@ -7,6 +7,8 @@ import (
"slices" "slices"
"strconv" "strconv"
"strings" "strings"
"gopkg.in/yaml.v3"
) )
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo) 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) files := getPackageFiles(pkgInfo.Name, rootDir)
localInfo := getPackageLocalInfo(pkgInfo.Name, rootDir)
return &BPMPackage{ return &BPMPackage{
PkgInfo: pkgInfo, PkgInfo: pkgInfo,
PkgFiles: files, PkgFiles: files,
LocalInfo: localInfo,
} }
} }
@@ -234,3 +238,28 @@ func getPackageFiles(pkg, rootDir string) []*PackageFileEntry {
return pkgFiles 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" "strconv"
"strings" "strings"
"syscall" "syscall"
"time"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
type BPMPackage struct { type BPMPackage struct {
PkgInfo *PackageInfo PkgInfo *PackageInfo
PkgFiles []*PackageFileEntry PkgFiles []*PackageFileEntry
LocalInfo PackageLocalInfo
} }
type PackageInfo struct { type PackageInfo struct {
@@ -75,6 +77,11 @@ type PackageFileEntry struct {
SizeInBytes int64 SizeInBytes int64
} }
type PackageLocalInfo struct {
InstalledOn int64 `yaml:"installed_on"`
LastUpdatedOn int64 `yaml:"last_updated_on"`
}
func (pkg *BPMPackage) GetInstalledSize() int64 { func (pkg *BPMPackage) GetInstalledSize() int64 {
var totalSize int64 = 0 var totalSize int64 = 0
for _, entry := range pkg.PkgFiles { for _, entry := range pkg.PkgFiles {
@@ -979,6 +986,24 @@ func installPackage(filename, rootDir string, verbose, force bool) error {
return err 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 // Save remove package scripts
packageScripts, err := ReadPackageScripts(filename) packageScripts, err := ReadPackageScripts(filename)
if err != nil { if err != nil {