fix: find_oldest and find_newest fixes

This commit is contained in:
Peter Šurda 2021-02-28 09:58:49 +01:00
parent 53450aaf5f
commit da6118b6a0
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 14 additions and 18 deletions

View File

@ -53,28 +53,24 @@ function find_oldest
{ {
local drive="$1" local drive="$1"
oldest="$(parted -m "$drive" -- print|awk -F: \ oldest="$(parted -m "$drive" -- print|awk -F: \
'BEGIN 'BEGIN {min="zzzzz"}
{min="ZZZZ"} {if (NR > 2 && $1 >= 2 && $1 <= 4 &&
{if (NR > 2 && $1 >= 2 && $1 <= 4 && $6 < min && $6 != "root unused") {
$6 < min && $6 != "root unused") { min=$6; part=$1
min=$6; part=$1 }}
}} END {print part}')"
END
{print part}')"
} }
function find_newest function find_newest
{ {
local drive="$1" local drive="$1"
newest="$(parted -m "$drive" -- print|awk -F: \ newest="$(parted -m "$drive" -- print|awk -F: \
'BEGIN 'BEGIN {max=""}
{max=""} {if (NR > 2 && $1 >= 2 && $1 <= 4 &&
{if (NR > 2 && $1 >= 2 && $1 <= 4 && $6 > max && $6 != "root unused") {
$6 > max && $6 != "root unused") { max=$6; part=$1
max=$6; part=$1 }}
}} END {print part}')"
END
{print part}')"
} }
function version_from_partnum function version_from_partnum

View File

@ -28,13 +28,13 @@ function test_partitioning()
rename_partition "$img" 3 "root $min_version" rename_partition "$img" 3 "root $min_version"
find_oldest "$img" find_oldest "$img"
assertEquals "find_oldest" "$min_version" "$oldest" assertEquals "find_oldest" 3 "$oldest"
version_from_partnum "$img" 3 version_from_partnum "$img" 3
assertEquals "version_from partnum 3" "$min_version" "$version" assertEquals "version_from partnum 3" "$min_version" "$version"
rename_partition "$img" 4 "root $max_version" rename_partition "$img" 4 "root $max_version"
find_newest "$img" find_newest "$img"
assertEquals "find_newest" "$max_version" "$newest" assertEquals "find_newest" 4 "$newest"
version_from_partnum "$img" 4 version_from_partnum "$img" 4
assertEquals "version_from_partnum 4" "$max_version" "$version" assertEquals "version_from_partnum 4" "$max_version" "$version"