mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: refactor losetup -d ... into free_loop_device_insistent() which retries 10 times
This commit is contained in:
@@ -51,18 +51,8 @@ function check_loop_device_internal() {
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
|
||||
#
|
||||
# This file is licensed under the terms of the GNU General Public
|
||||
# License version 2. This program is licensed "as is" without any
|
||||
# warranty of any kind, whether express or implied.
|
||||
#
|
||||
# This file is a part of the Armbian build script
|
||||
# https://github.com/armbian/build/
|
||||
|
||||
# write_uboot <loopdev>
|
||||
#
|
||||
# write_uboot_to_loop_image <loopdev>
|
||||
# @TODO: isnt this supposed to be u-boot related? why in loop.sh?
|
||||
write_uboot_to_loop_image() {
|
||||
|
||||
local loop=$1 revision
|
||||
@@ -102,3 +92,14 @@ write_uboot_to_loop_image() {
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# This exists to prevent silly failures; sometimes the user is inspecting the directory outside of build, etc.
|
||||
function free_loop_device_insistent() {
|
||||
display_alert "Freeing loop device" "${1}"
|
||||
do_with_retries 10 free_loop_device_retried "${1}"
|
||||
}
|
||||
|
||||
function free_loop_device_retried() {
|
||||
display_alert "Freeing loop device (try ${RETRY_RUNS})" "${1}"
|
||||
losetup -d "${1}"
|
||||
}
|
||||
|
||||
@@ -88,8 +88,7 @@ create_image_from_sdcard_rootfs() {
|
||||
Called after unmounting both `/root` and `/boot`.
|
||||
POST_UMOUNT_FINAL_IMAGE
|
||||
|
||||
display_alert "Freeing loop device" "${LOOP}"
|
||||
losetup -d "${LOOP}"
|
||||
free_loop_device_insistent "${LOOP}"
|
||||
unset LOOP # unset so cleanup handler does not try it again
|
||||
|
||||
# We're done with ${MOUNT} by now, remove it.
|
||||
|
||||
@@ -129,7 +129,7 @@ function trap_handler_cleanup_rootfs_and_image() {
|
||||
# shellcheck disable=SC2153 # global var.
|
||||
if [[ -b "${LOOP}" ]]; then
|
||||
display_alert "Freeing loop" "trap_handler_cleanup_rootfs_and_image ${LOOP}" "wrn"
|
||||
losetup -d "${LOOP}" >&2 || true
|
||||
free_loop_device_insistent "${LOOP}" || true
|
||||
fi
|
||||
|
||||
[[ -d "${SDCARD}" ]] && rm -rf --one-file-system "${SDCARD}"
|
||||
|
||||
Reference in New Issue
Block a user