Use temp file for du calculations
Storing the du output in a variable seemed convenient, but I didn't realise just how big it could get especially with things like infra images -- there's something like 100MiB of text being stored in a bash variable here. Convert this to work with a temporary file Change-Id: I6a6d22c2142e0f199490c39cca8c94769e4b0232
This commit is contained in:
parent
c1bac651cb
commit
48daefb685
@ -338,26 +338,28 @@ mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
|
||||
# logs with du output below.
|
||||
xtrace=$(set +o | grep xtrace)
|
||||
|
||||
# temp file for holding du output
|
||||
du_output=${TMP_BUILD_DIR}/du_output.tmp
|
||||
|
||||
if [ -n "$DIB_IMAGE_SIZE" ]; then
|
||||
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
||||
else
|
||||
set +o xtrace
|
||||
echo "Calculating image size (this may take a minute)..."
|
||||
du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
|
||||
sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output}
|
||||
# the last line is the total size from "-c".
|
||||
# scale this by 0.6 to create a slightly bigger image
|
||||
du_size=$(echo "$du_output" | tail -n1 | cut -f1 | \
|
||||
awk '{print int($1 / 0.6)}')
|
||||
du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}')
|
||||
$xtrace
|
||||
fi
|
||||
|
||||
if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
||||
set +o xtrace
|
||||
if [ -z "$du_output" ]; then
|
||||
du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
|
||||
if [ ! -f "$du_output" ]; then
|
||||
sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output}
|
||||
fi
|
||||
|
||||
du_output_show="sort -nr |
|
||||
du_output_show="sort -nr ${du_output} |
|
||||
numfmt --to=iec-i --padding=7
|
||||
--suffix=B --field=1 --from-unit=1024"
|
||||
|
||||
@ -376,7 +378,7 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
||||
echo "================="
|
||||
fi
|
||||
|
||||
eval ${du_output_show} <<< "$du_output"
|
||||
eval ${du_output_show}
|
||||
|
||||
echo
|
||||
echo "===== end image size report ====="
|
||||
@ -385,6 +387,8 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
||||
$xtrace
|
||||
fi
|
||||
|
||||
rm -f ${du_output}
|
||||
|
||||
if [ "$FS_TYPE" = "ext4" ] ; then
|
||||
# Very conservative to handle images being resized a lot
|
||||
# We set journal size to 64M so our journal is large enough when we
|
||||
|
Loading…
Reference in New Issue
Block a user