From a758e59d462d9ca2c00c79b9f52b7dce52fd0e1c Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 3 Jul 2023 13:13:54 +0200 Subject: [PATCH] fix: Fallback to truncate if allocate fails --- run/disk.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index 53403df..6d5ef85 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -26,7 +26,9 @@ if [ -f "${DATA}" ]; then if [[ "${ALLOCATE}" == [Nn]* ]]; then # Resize file by changing its length - truncate -s "${DATA_SIZE}" "${DATA}"; + if ! truncate -s "${DATA_SIZE}" "${DATA}"; then + error "Could not resize the file for the data disk." && exit 85 + fi else @@ -42,7 +44,9 @@ if [ -f "${DATA}" ]; then # Resize file by allocating more space if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - error "Could not allocate a file for the data disk." && exit 85 + if ! truncate -s "${DATA_SIZE}" "${DATA}"; then + error "Could not resize the file for the data disk." && exit 85 + fi fi if [[ "${ALLOCATE}" == [Zz]* ]]; then @@ -71,7 +75,10 @@ if [ ! -f "${DATA}" ]; then if [[ "${ALLOCATE}" == [Nn]* ]]; then # Create an empty file - truncate -s "${DATA_SIZE}" "${DATA}" + if ! truncate -s "${DATA_SIZE}" "${DATA}"; then + rm -f "${DATA}" + error "Could not create a file for the data disk." && exit 87 + fi else @@ -85,8 +92,10 @@ if [ ! -f "${DATA}" ]; then # Create an empty file if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - rm -f "${DATA}" - error "Could not allocate a file for the data disk." && exit 87 + if ! truncate -s "${DATA_SIZE}" "${DATA}"; then + rm -f "${DATA}" + error "Could not create a file for the data disk." && exit 87 + fi fi if [[ "${ALLOCATE}" == [Zz]* ]]; then