- Add lazy mount - Add check if dir exists - Add check if dir mounted - Remove infinity loop and Add 3 attempts for unmount
43 lines
1.4 KiB
Diff
43 lines
1.4 KiB
Diff
diff --git a/pbuilder-modules b/pbuilder-modules
|
|
index 14e61e5..9e7641f 100644
|
|
--- a/pbuilder-modules
|
|
+++ b/pbuilder-modules
|
|
@@ -234,6 +234,24 @@
|
|
log.i "ignoring umount of $1 filesystem"
|
|
return
|
|
fi
|
|
+ if [ ! -d "$BUILDPLACE/$1" ]; then
|
|
+ log.w "Directory $BUILDPLACE/$1 does not exist, skipping unmount."
|
|
+ return
|
|
+ fi
|
|
+ # Running lsof to check if dir is busy
|
|
+ log.i "Running lsof on $1"
|
|
+ if ! lsof_output=$(lsof | grep "$1" 2>/dev/null); then
|
|
+ log.w "lsof command failed for $1, continuing..."
|
|
+ elif [ -z "$lsof_output" ]; then
|
|
+ log.i "No open files found for $1"
|
|
+ else
|
|
+ log.i "Open files for $1:\n$lsof_output"
|
|
+ fi
|
|
+ # Check if it's mounted before unmounting
|
|
+ if ! mount | grep -q "$BUILDPLACE/$1"; then
|
|
+ log.i "$BUILDPLACE/$1 is not mounted, skipping unmount."
|
|
+ return
|
|
+ fi
|
|
log.i "unmounting $1 filesystem"
|
|
local UMOUNT_OUTPUT
|
|
if ! UMOUNT_OUTPUT="$(LC_ALL=C umount "$BUILDPLACE/$1" 2>&1)"; then
|
|
@@ -255,7 +273,12 @@
|
|
if [ "$ignore_umount_error" != "yes" ]; then
|
|
log.w "Retrying to unmount $1 in 5s"
|
|
sleep 5s
|
|
- while ! umount "$BUILDPLACE/$1"; do
|
|
+ attempt=0
|
|
+ while [ $attempt -lt 2 ]; do
|
|
+ if umount -l "$BUILDPLACE/$1"; then
|
|
+ break
|
|
+ fi
|
|
+ attempt=$((attempt + 1))
|
|
sleep 5s
|
|
cat <<EOF
|