Merge "Use temp file for du calculations"
This commit is contained in:
commit
1a8dc59871
@ -338,26 +338,28 @@ mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
|
|||||||
# logs with du output below.
|
# logs with du output below.
|
||||||
xtrace=$(set +o | grep xtrace)
|
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
|
if [ -n "$DIB_IMAGE_SIZE" ]; then
|
||||||
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
||||||
else
|
else
|
||||||
set +o xtrace
|
set +o xtrace
|
||||||
echo "Calculating image size (this may take a minute)..."
|
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".
|
# the last line is the total size from "-c".
|
||||||
# scale this by 0.6 to create a slightly bigger image
|
# scale this by 0.6 to create a slightly bigger image
|
||||||
du_size=$(echo "$du_output" | tail -n1 | cut -f1 | \
|
du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}')
|
||||||
awk '{print int($1 / 0.6)}')
|
|
||||||
$xtrace
|
$xtrace
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
||||||
set +o xtrace
|
set +o xtrace
|
||||||
if [ -z "$du_output" ]; then
|
if [ ! -f "$du_output" ]; then
|
||||||
du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
|
sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
du_output_show="sort -nr |
|
du_output_show="sort -nr ${du_output} |
|
||||||
numfmt --to=iec-i --padding=7
|
numfmt --to=iec-i --padding=7
|
||||||
--suffix=B --field=1 --from-unit=1024"
|
--suffix=B --field=1 --from-unit=1024"
|
||||||
|
|
||||||
@ -376,7 +378,7 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
|||||||
echo "================="
|
echo "================="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval ${du_output_show} <<< "$du_output"
|
eval ${du_output_show}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "===== end image size report ====="
|
echo "===== end image size report ====="
|
||||||
@ -385,6 +387,8 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
|||||||
$xtrace
|
$xtrace
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f ${du_output}
|
||||||
|
|
||||||
if [ "$FS_TYPE" = "ext4" ] ; then
|
if [ "$FS_TYPE" = "ext4" ] ; then
|
||||||
# Very conservative to handle images being resized a lot
|
# Very conservative to handle images being resized a lot
|
||||||
# We set journal size to 64M so our journal is large enough when we
|
# We set journal size to 64M so our journal is large enough when we
|
||||||
|
Loading…
Reference in New Issue
Block a user