Skip to content

Commit 7bb1e88

Browse files
committed
[fix] : FIxed them bug that script will unmount all mountpoint
1 parent a2e382d commit 7bb1e88

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

build.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,19 @@ _mount() { if ! mountpoint -q "${2}" && [[ -f "${1}" ]] && [[ -d "${2}" ]]; then
197197
# Unmount chroot dir
198198
umount_chroot () {
199199
local _mount
200-
if [[ ! -v build_dir ]] || [[ "${build_dir}" = "" ]]; then
200+
if [[ ! -v "build_dir" ]] || [[ "${build_dir}" = "" ]]; then
201201
msg_error "Exception error about working directory" 1
202202
fi
203-
for _mount in $(cat /proc/mounts | getclm 2 | grep "$(realpath ${build_dir})" | tac | grep -xv "$(realpath ${build_dir})/${arch}/airootfs"); do
204-
msg_info "Unmounting ${_mount}"
205-
_umount "${_mount}" 2> /dev/null
203+
if [[ ! -d "${build_dir}" ]]; then
204+
return 0
205+
fi
206+
for _mount in $(cat "/proc/mounts" | getclm 2 | grep "$(realpath -s ${build_dir})" | tac | grep -xv "$(realpath -s ${build_dir})/${arch}/airootfs"); do
207+
if echo "${_mount}" | grep "${work_dir}" > /dev/null 2>&1 || echo "${_mount}" | grep "${script_path}" > /dev/null 2>&1 || echo "${_mount}" | grep "${out_dir}" > /dev/null 2>&1; then
208+
msg_info "Unmounting ${_mount}"
209+
_umount "${_mount}" 2> /dev/null
210+
else
211+
msg_error "It is dangerous to unmount a directory that is not managed by the script."
212+
fi
206213
done
207214
}
208215

0 commit comments

Comments
 (0)