From 8b6624cf2fb0265deeac0daa3f7367c116ec2010 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 8 Aug 2026 15:51:56 +0200 Subject: [PATCH] fix: Do not fail if marker cannot be created (#1359) --- src/disk.sh | 16 ------ src/power.sh | 2 +- src/utils.sh | 150 ++++++++++++++++++++++++++++----------------------- 3 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 16849b6..35c6953 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -200,22 +200,6 @@ normalizeSize() { return 0 } -baseDir() { - - local path="${1%/}" - - [[ -z "$path" || "$path" == "/" ]] && { - echo "/" - return 0 - } - - path="${path#/}" - path="${path%%/*}" - - echo "/$path" - return 0 -} - freeSpace() { local path="$1" diff --git a/src/power.sh b/src/power.sh index 6008d76..91d9d21 100644 --- a/src/power.sh +++ b/src/power.sh @@ -217,7 +217,7 @@ finish() { failed=1 fi - touch "$QEMU_END" + touch "$QEMU_END" || : forceKillQemu "$reason" cleanupHelpers diff --git a/src/utils.sh b/src/utils.sh index e5e02f0..193f144 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -123,32 +123,6 @@ disabled() { esac } -formatBytes() { - - local result - - if ! result=$(numfmt --to=iec --suffix=B "$1" | sed -r 's/([A-Z])/ \1/' | sed 's/ B/ bytes/g;'); then - return 1 - fi - - local unit="${result//[0-9. ]}" - result="${result//[a-zA-Z ]/}" - - if [[ "${2:-}" == "up" ]]; then - if [[ "$result" == *"."* ]]; then - result="${result%%.*}" - result=$((result+1)) - fi - else - if [[ "${2:-}" == "down" ]]; then - result="${result%%.*}" - fi - fi - - echo "$result $unit" - return 0 -} - isAlive() { local pid="$1" @@ -272,47 +246,6 @@ mKill() { return 0 } -setOwner() { - - local file="$1" - local dir uid gid - - [ ! -f "$file" ] && return 1 - - # Match generated files to the owner of their bind-mounted parent directory - # instead of assuming a fixed container or host UID. - dir=$(dirname -- "$file") - uid=$(stat -c '%u' "$dir") || return 1 - gid=$(stat -c '%g' "$dir") || return 1 - - chown "$uid:$gid" "$file" || return 1 - - return 0 -} - -makeDir() { - - local path="$1" - local dir uid gid - - [ -d "$path" ] && return 0 - mkdir -p "$path" || return 1 - - dir=$(dirname -- "$path") - - if ! uid=$(stat -c '%u' "$dir") || ! gid=$(stat -c '%g' "$dir"); then - warn "failed to determine the owner for \"$path\"." - return 0 - fi - - if ! chown "$uid:$gid" "$path"; then - warn "failed to set the owner for \"$path\"." - return 0 - fi - - return 0 -} - finiteMemoryLimit() { local limit="$1" @@ -371,6 +304,89 @@ getMemoryInfo() { return 0 } +baseDir() { + + local path="${1%/}" + + [[ -z "$path" || "$path" == "/" ]] && { + echo "/" + return 0 + } + + path="${path#/}" + path="${path%%/*}" + + echo "/$path" + return 0 +} + +formatBytes() { + + local result + + if ! result=$(numfmt --to=iec --suffix=B "$1" | sed -r 's/([A-Z])/ \1/' | sed 's/ B/ bytes/g;'); then + return 1 + fi + + local unit="${result//[0-9. ]}" + result="${result//[a-zA-Z ]/}" + + if [[ "${2:-}" == "up" ]]; then + if [[ "$result" == *"."* ]]; then + result="${result%%.*}" + result=$((result+1)) + fi + else + if [[ "${2:-}" == "down" ]]; then + result="${result%%.*}" + fi + fi + + echo "$result $unit" + return 0 +} + +setOwner() { + + local file="$1" + local dir uid gid + + [ ! -f "$file" ] && return 1 + + # Match generated files to the owner of their bind-mounted parent directory + # instead of assuming a fixed container or host UID. + dir=$(dirname -- "$file") + uid=$(stat -c '%u' "$dir") || return 1 + gid=$(stat -c '%g' "$dir") || return 1 + + chown "$uid:$gid" "$file" || return 1 + + return 0 +} + +makeDir() { + + local path="$1" + local dir uid gid + + [ -d "$path" ] && return 0 + mkdir -p "$path" || return 1 + + dir=$(dirname -- "$path") + + if ! uid=$(stat -c '%u' "$dir") || ! gid=$(stat -c '%g' "$dir"); then + warn "failed to determine the owner for \"$path\"." + return 0 + fi + + if ! chown "$uid:$gid" "$path"; then + warn "failed to set the owner for \"$path\"." + return 0 + fi + + return 0 +} + stateFile() { local name="$1"