Enhance robustness against poor/corrupt installed package data

This commit is contained in:
prpr 2024-04-07 14:32:29 +01:00
parent 0ee83fa950
commit db67239313
1 changed files with 49 additions and 14 deletions

View File

@ -13,12 +13,11 @@ class pkg {
set ::pkgmeta {}
set ::diagmeta {}
set ::muxdb {}
pkg method _load {nm} {
set name $nm
set latest 0
foreach line [split [exec /bin/opkg list $nm] "\n"] {
foreach line [split [pkg list $nm] "\n"] {
# betaftpd - 0.0.8pre17-1 - Description...
if {[string match { *} $line]} {
append descr $line
@ -33,12 +32,9 @@ pkg method _load {nm} {
}
if {$descr eq ""} {
$self loadraw
if {[dict exists $raw description]} {
set descr $raw(description)
}
}
regexp {(.*) \[(.*)\]} $descr x descr changes
set info [exec /bin/opkg list-installed $nm]
set info [pkg listinst $nm]
regexp {^([^ ]+) - ([^ ]+)$} $info x x installed
return $self
@ -48,7 +44,7 @@ proc {pkg instverlist} {} {{cache {}}} {
if {[llength $cache]} { return $cache }
# Fetch details of installed packages
foreach line [split [exec /bin/opkg list-installed] "\n"] {
foreach line [split [pkg listinst] "\n"] {
lassign $line pkg x ver
set cache($pkg) $ver
}
@ -126,7 +122,7 @@ pkg method loadraw {} {
if {[file exists "/mod/var/opkg/info/$name.control"]} {
set data [file read "/mod/var/opkg/info/$name.control"]
} else {
set data [exec /bin/opkg info $name]
set data [pkg info $name]
}
foreach line [split $data "\n"] {
@ -135,7 +131,7 @@ pkg method loadraw {} {
continue
}
regexp {^([^:]+): (.*)$} $line x tag txt
if {![dict exists $raw $tag]} {
if {$tag ne "" && $txt ne "" && ![dict exists $raw $tag]} {
set tag [string tolower $tag]
set raw($tag) $txt
} else {
@ -144,6 +140,7 @@ pkg method loadraw {} {
}
if {[dict exists $raw tags]} { set url $raw(tags) }
if {![dict exists $raw description]} { set descr [set raw(description) "Unknown"] }
}
proc {pkg load} {nm} {
@ -167,7 +164,7 @@ pkg method is {what} {
proc {pkg avail} {} {
set inst_pkgs [pkg inst]
set avail_pkgs {}
foreach pkg [split [exec /bin/opkg list] "\n"] {
foreach pkg [split [pkg list] "\n"] {
if {[regexp {^ } $pkg]} { continue }
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
if {$name ni $inst_pkgs && $name ni $avail_pkgs} {
@ -181,7 +178,7 @@ proc {pkg avail} {} {
proc {pkg inst} {} {
# Build a list of installed packages - just the names
set inst_pkgs {}
foreach pkg [split [exec /bin/opkg list-installed] "\n"] {
foreach pkg [split [pkg listinst] "\n"] {
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
if {$name ni $inst_pkgs} {
lappend inst_pkgs $name
@ -194,7 +191,7 @@ proc {pkg inst} {} {
proc {pkg upgr} {} {
#webif - 0.5.3 - 0.5.7
set upgr_pkgs {}
foreach pkg [split [exec /bin/opkg list-upgradable] "\n"] {
foreach pkg [split [pkg listupgr] "\n"] {
if {[regexp {^([^ ]+)} $pkg name] == 0} { continue }
lappend upgr_pkgs $name
#puts "Upgr: $name<br>"
@ -261,8 +258,42 @@ proc {pkg fetchdiagmeta} {} {
$ff close
}
proc {pkg removemuxdb} {} {
file delete "/mod/var/mux.db"
proc {pkg list} {{nm ""}} {
catch {
if {$nm eq ""} {
exec /bin/opkg list | grep -v "valid architecture"
} else {
exec /bin/opkg list $nm | grep -v "valid architecture"
}
} msg
return $msg
}
proc {pkg listinst} {{nm ""}} {
catch {
if {$nm eq ""} {
exec /bin/opkg list-installed | grep -v "valid architecture"
} else {
exec /bin/opkg list-installed $nm | grep -v "valid architecture"
}
} msg
return $msg
}
proc {pkg listupgr} {} {
catch {exec /bin/opkg list-upgradable | grep -v "valid architecture"} msg
return $msg
}
proc {pkg info} {{nm ""}} {
catch {
if {$nm eq ""} {
exec /bin/opkg info | grep -v "valid architecture"
} else {
exec /bin/opkg info $nm | grep -v "valid architecture"
}
} msg
return $msg
}
proc {pkg update} {} {
@ -273,6 +304,10 @@ proc {pkg upgrade} {nm} {
exec /bin/opkg upgrade $nm
}
proc {pkg removemuxdb} {} {
file delete "/mod/var/mux.db"
}
proc {pkg vercompare} {v1 v2} {
if {$v1 eq $v2} { return 0 }