From 81a3f1e5ffd4ce73297ab0756ed1231b926b5fc8 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 02 Aug 2012 00:13:03 -0400 Subject: Calculate installed size of packages. --- (limited to 'lib') diff --git a/lib/control.sh b/lib/control.sh index e07b04d..6fa8931 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -72,7 +72,8 @@ oh_control_gen_source() OH_CONTROL_BINARY_FIELD_RECOMMENDS="${OH_CONTROL_SOURCE_FIELD_BUILD_DEPENDS}" OH_CONTROL_BINARY_FIELD_DESCRIPTION="${OH_SOURCE} source package" - _control_gen 'SOURCE' "src:${OH_SOURCE}.control/control" + _control_gen 'SOURCE' \ + "src:${OH_SOURCE}.control/control" "src:${OH_SOURCE}.data" OH_CONTROL_BINARY_FIELD_PACKAGE="${_old_package}" OH_BINARY_VERSION="${_old_version}" @@ -83,7 +84,8 @@ oh_control_gen_source() oh_control_gen_binary() { - _control_gen 'BINARY' "${1}.control/control" + _control_gen 'BINARY' \ + "${1}.control/control" "${1}.data" } _control_parse() @@ -179,9 +181,36 @@ _control_gen() { _type="${1}" _control="${2}" + _data="${2}" # TODO: Handle platforms and architectures like "any" and "any-linux-any". - # TODO: Calculate installed size. + + # Calculate installed size. + # Don't use du, since that considers the allocated size of files, symbolic + # links, and directories (i.e. actual file sizes plus the filesystem + # overhead on the build system). + # See the following for more information: + # + # + # + _sizes="$(find "${_data}" -type f -exec wc -c '{}' ';' | cut -d ' ' -f 1)" + _inst_size=0 + for _size in ${_sizes}; do + _inst_size=$(($_inst_size + $_size)) + done + # Convert bytes to kibibytes and round up. + # Note: There is an inconsistency between the Debian Policy Manual and opkg + # in the units of this field. Debian Policy defines this field in units of + # kibibytes: + # The disk space is given as the integer value of the estimated installed + # size in bytes, divided by 1024 and rounded up. + # However, opkg apparently attempts to convert this value from bytes to + # kibibytes in its determination of whether the package's data will fit on + # the system: + # pkg_size_kbs = (pkg->installed_size + 1023)/1024; + # TODO: Further investigate opkg's disk space calculation and, if necessary, + # patch opkg and submit a bug report. + _inst_size=$((($inst_size + 1023) / 1024)) cat >"${_control}" <