mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-21 23:09:14 +02:00
Refactor mount testing logic for improved clarity
This commit is contained in:
@@ -23,52 +23,51 @@ cleanup_cred() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_mount() {
|
test_mount() {
|
||||||
local _werr
|
|
||||||
MOUNTED=false
|
MOUNTED=false
|
||||||
ERROR_MOUNT=false
|
ERROR_MOUNT=false
|
||||||
|
mountpoint="/mnt/$diskname"
|
||||||
|
|
||||||
if ! mountpoint -q "/mnt/$diskname"; then
|
# Not mounted → not an error for this function
|
||||||
|
if ! mountpoint -q "$mountpoint"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -e "/mnt/$diskname/testaze" ]] && rm -rf "/mnt/$diskname/testaze"
|
# ---- Write test function ----
|
||||||
_werr="$(mktemp /tmp/mount_write_test.XXXXXX)"
|
_test_write() {
|
||||||
: >"$_werr" || true
|
local testfile="$mountpoint/.writetest_$$"
|
||||||
mkdir "/mnt/$diskname/testaze" 2>"$_werr" \
|
if : > "$testfile" 2>/dev/null; then
|
||||||
&& touch "/mnt/$diskname/testaze/testaze" 2>>"$_werr" \
|
rm -f "$testfile"
|
||||||
&& rm -rf "/mnt/$diskname/testaze" 2>>"$_werr" \
|
return 0
|
||||||
|| ERROR_MOUNT=true
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Accept read-only mounts: warn but do not fail
|
# First write test
|
||||||
if [[ "$ERROR_MOUNT" == "true" ]] && grep -qiE 'read-only file system|EROFS' "$_werr" 2>/dev/null; then
|
if _test_write; then
|
||||||
bashio::log.warning "Disk is mounted but READ-ONLY (/mnt/$diskname). Write test failed due to read-only filesystem. Continuing."
|
|
||||||
rm -f "$_werr" 2>/dev/null || true
|
|
||||||
MOUNTED=true
|
MOUNTED=true
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
rm -f "$_werr" 2>/dev/null || true
|
|
||||||
|
|
||||||
# CIFS-only: noserverino fallback
|
# ---- CIFS fallback check ----
|
||||||
if [[ "$ERROR_MOUNT" == "true" && "$FSTYPE" == "cifs" ]]; then
|
if [[ "$FSTYPE" == "cifs" && "$MOUNTOPTIONS" != *"noserverino"* ]]; then
|
||||||
if [[ "$MOUNTOPTIONS" == *"noserverino"* ]]; then
|
echo "... retrying mount with noserverino"
|
||||||
bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
MOUNTOPTIONS="${MOUNTOPTIONS},noserverino"
|
MOUNTOPTIONS="${MOUNTOPTIONS},noserverino"
|
||||||
echo "... testing with noserverino"
|
|
||||||
mount_drive "$MOUNTOPTIONS"
|
umount "$mountpoint" 2>/dev/null
|
||||||
return 0
|
if mount_drive "$MOUNTOPTIONS"; then
|
||||||
|
# retest with new options
|
||||||
|
if _test_write; then
|
||||||
|
MOUNTED=true
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# IMPORTANT: do not claim success when mounted but not writable (all FS types)
|
# ---- Final: mounted but not writable ----
|
||||||
if [[ "$ERROR_MOUNT" == "true" ]]; then
|
ERROR_MOUNT=true
|
||||||
MOUNTED=false
|
bashio::log.fatal "Disk mounted, but cannot write. Check permissions/export options and UID/GID mapping."
|
||||||
bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check permissions/export options (rw), and UID/GID mapping."
|
return 1
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
MOUNTED=true
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_drive() {
|
mount_drive() {
|
||||||
|
|||||||
Reference in New Issue
Block a user