summaryrefslogtreecommitdiffstats
path: root/src/block.sh
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-01-17 16:10:31 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-01-17 16:10:31 (EST)
commit09c583248e7c0aa5a833ec01262b8b4a7980234b (patch)
treee3ecd4028e888d6eb587d9703ace4d90396a624a /src/block.sh
parentd5e46c35ea98e43b6ad380ac7fbc197b7881b220 (diff)
parente3ab87a78aafd979f6eb8bb75ef70304d87a1d6b (diff)
Merge branch 'feature/improve-error-handling'
Diffstat (limited to 'src/block.sh')
-rw-r--r--src/block.sh19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/block.sh b/src/block.sh
index f056305..ad94bde 100644
--- a/src/block.sh
+++ b/src/block.sh
@@ -31,7 +31,8 @@ check_block()
local dev="${1}"
if ! [ -b "${dev}" ]; then
- error 2 "$(get_msg 'block_device_invalid')" "${dev}"
+ error "$(get_msg 'block_device_invalid')" "${dev}"
+ return 1
fi
}
@@ -40,17 +41,21 @@ block_mount()
local dev="${1}"
local dir=
- check_block "${dev}"
+ if ! check_block "${dev}"; then
+ return 2
+ fi
rand
dir="$(get_vardata_dir 'mount')/block-$(printf '%010d' ${rand_x})"
if ! mkdir "${dir}"; then
- error 2 "$(get_msg 'block_mkdir_fail')" "${dir}"
+ error "$(get_msg 'block_mkdir_fail')" "${dir}"
+ return 1
fi
if ! mount "${dev}" "${dir}"; then
+ error "$(get_msg 'block_mount_fail')" "${dev}"
rmdir "${dir}"
- error 2 "$(get_msg 'block_mount_fail')" "${dev}"
+ return 1
fi
printf '%s' "${dir}"
@@ -75,11 +80,13 @@ block_umount()
done
if ${timed_out}; then
- error 2 "$(get_msg 'block_umount_fail')" "${dir}"
+ error "$(get_msg 'block_umount_fail')" "${dir}"
+ return 1
fi
if ! rmdir "${dir}"; then
- error 2 "$(get_msg 'block_rmdir_fail')" "${dir}"
+ error "$(get_msg 'block_rmdir_fail')" "${dir}"
+ return 1
fi
return 0