cleanup in separate function do_unmount
authorIvo De Decker <ivo.dedecker@ugent.be>
Sat, 13 Jul 2013 19:13:05 +0000 (21:13 +0200)
committerColin Watson <cjwatson@debian.org>
Thu, 19 Jan 2017 21:01:39 +0000 (21:01 +0000)
linux-boot-probes/common/50mounted-tests
os-probes/common/50mounted-tests

index 91b6dd9..992af2b 100755 (executable)
@@ -3,6 +3,16 @@
 . /usr/share/os-prober/common.sh
 set -e
 
+do_unmount() {
+       if [ "$mounted" ]; then
+               umount "$tmpmnt/boot" 2>/dev/null || true
+               if ! umount "$tmpmnt"; then
+                       warn "failed to umount $tmpmnt"
+               fi
+       fi
+       rmdir "$tmpmnt" || true
+}
+
 partition="$1"
 
 types="$(fs_type "$partition")" || types=NOT-DETECTED
@@ -64,23 +74,13 @@ if [ "$mounted" ]; then
                        debug "running $test $partition $bootpart $tmpmnt $type"
                        if $test "$partition" "$bootpart" "$tmpmnt" "$type"; then
                                debug "$test succeeded"
-                               umount "$tmpmnt/boot" 2>/dev/null || true       
-                               if ! umount "$tmpmnt"; then
-                                       warn "failed to umount $tmpmnt"
-                               fi
-                               rmdir "$tmpmnt" || true
+                               do_unmount
                                exit 0
                        fi
                fi
        done
-
-       umount "$tmpmnt/boot" 2>/dev/null || true       
-       if ! umount "$tmpmnt"; then
-               warn "failed to umount $tmpmnt"
-       fi
 fi
-
-rmdir "$tmpmnt" || true
+do_unmount
 
 # No tests found anything.
 exit 1
index 561163b..52a5441 100755 (executable)
@@ -5,6 +5,15 @@ partition="$1"
 
 . /usr/share/os-prober/common.sh
 
+do_unmount() {
+       if [ "$mounted" ]; then
+               if ! umount "$tmpmnt"; then
+                       warn "failed to umount $tmpmnt"
+               fi
+       fi
+       rmdir "$tmpmnt" || true
+}
+
 types="$(fs_type "$partition")" || types=NOT-DETECTED
 if [ "$types" = NOT-DETECTED ]; then
        debug "$1 type not recognised; skipping"
@@ -74,20 +83,13 @@ if [ "$mounted" ]; then
                if [ -f "$test" ] && [ -x "$test" ]; then
                        if "$test" "$partition" "$tmpmnt" "$type"; then
                                debug "os found by subtest $test"
-                               if ! umount "$tmpmnt"; then
-                                       warn "failed to umount $tmpmnt"
-                               fi
-                               rmdir "$tmpmnt" || true
+                               do_unmount
                                exit 0
                        fi
                fi
        done
-       if ! umount "$tmpmnt"; then
-               warn "failed to umount $tmpmnt"
-       fi
 fi
-
-rmdir "$tmpmnt" || true
+do_unmount
 
 # No tests found anything.
 exit 1