Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o, Justin Lecher <jlec@g.o>
Cc: qa@g.o, Justin Lecher <jlec@g.o>
Subject: Re: [gentoo-dev] [PATCH] check-reqs.eclass: Replace obsolete df option -m with -k
Date: Mon, 28 Dec 2015 15:42:02
Message-Id: 05DC1E60-5FDB-46DD-A678-CD0CCF9B6D07@gentoo.org
In Reply to: [gentoo-dev] [PATCH] check-reqs.eclass: Replace obsolete df option -m with -k by Justin Lecher
1 Dnia 28 grudnia 2015 16:27:43 CET, Justin Lecher <jlec@g.o> napisał(a):
2 >Using kbi as base unit for calculation as linux and bsd only have -k as
3 >common option
4
5 It's 'kibibyte', or KiB in short.
6
7 >
8 >Signed-off-by: Justin Lecher <jlec@g.o>
9 >---
10 > eclass/check-reqs.eclass | 25 +++++++++++++------------
11 > 1 file changed, 13 insertions(+), 12 deletions(-)
12 >
13 >diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
14 >index 138bfec..a649693 100644
15 >--- a/eclass/check-reqs.eclass
16 >+++ b/eclass/check-reqs.eclass
17 >@@ -159,12 +159,12 @@ check-reqs_run() {
18 > fi
19 > }
20 >
21 >-# @FUNCTION: check-reqs_get_mebibytes
22 >+# @FUNCTION: check-reqs_get_kbibytes
23 > # @INTERNAL
24 > # @DESCRIPTION:
25 >-# Internal function that returns number in mebibytes.
26 >-# Returns 1024 for 1G or 1048576 for 1T.
27 >-check-reqs_get_mebibytes() {
28 >+# Internal function that returns number in kbibytes.
29 >+# Returns 1024**2 for 1G or 1024**3 for 1T.
30 >+check-reqs_get_kbibytes() {
31 > debug-print-function ${FUNCNAME} "$@"
32 >
33 > [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
34 >@@ -173,9 +173,10 @@ check-reqs_get_mebibytes() {
35 > local size=${1%[GMT]}
36 >
37 > case ${unit} in
38 >- G) echo $((1024 * size)) ;;
39 >- [M0-9]) echo ${size} ;;
40 >- T) echo $((1024 * 1024 * size)) ;;
41 >+ G) echo $((1024 * 1024 * size)) ;;
42 >+ M) echo $((1024 * size)) ;;
43 >+ T) echo $((1024 * 1024 * 1024 * size)) ;;
44 >+ [0-9]) echo $((1024 * size)) ;;
45 > *)
46 > die "${FUNCNAME}: Unknown unit: ${unit}"
47 > ;;
48 >@@ -275,7 +276,7 @@ check-reqs_memory() {
49 > actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
50 > fi
51 > if [[ -n ${actual_memory} ]] ; then
52 >- if [[ ${actual_memory} -lt $((1024 * $(check-reqs_get_mebibytes
53 >${size}))) ]] ; then
54 >+ if [[ ${actual_memory} -lt $(check-reqs_get_kbibytes ${size}) ]] ;
55 >then
56 > eend 1
57 > check-reqs_unsatisfied \
58 > ${size} \
59 >@@ -300,16 +301,16 @@ check-reqs_disk() {
60 >
61 > local path=${1}
62 > local size=${2}
63 >- local space_megs
64 >+ local space_kbi
65 >
66 > check-reqs_start_phase \
67 > ${size} \
68 > "disk space at \"${path}\""
69 >
70 >- space_megs=$(df -Pm "${1}" 2>/dev/null | awk 'FNR == 2 {print $4}')
71 >+ space_kbi=$(df -Pk "${1}" 2>/dev/null | awk 'FNR == 2 {print $4}')
72 >
73 >- if [[ $? == 0 && -n ${space_megs} ]] ; then
74 >- if [[ ${space_megs} -lt $(check-reqs_get_mebibytes ${size}) ]] ;
75 >then
76 >+ if [[ $? == 0 && -n ${space_kbi} ]] ; then
77 >+ if [[ ${space_kbi} -lt $(check-reqs_get_kbibytes ${size}) ]] ; then
78 > eend 1
79 > check-reqs_unsatisfied \
80 > ${size} \
81
82
83 --
84 Best regards,
85 Michał Górny (by phone)

Replies