]> arthur.barton.de Git - bup.git/blobdiff - t/cleanup-mounts-under
cleanup-mounts-under: Don't fail when /proc/mounts isn't readable
[bup.git] / t / cleanup-mounts-under
index 6d5cb873e5c704a5d497df75236a53bcece53244..8f766c321735ef10caa4d3350960331e44659195 100755 (executable)
@@ -17,16 +17,26 @@ targets = sys.argv[1:]
 exit_status = 0
 for target in targets:
     if not os.path.isdir(target):
-        print >> sys.stderr, target, 'is not a directory'
+        print >> sys.stderr, target, 'is not a directory!'
         exit_status = 1
         continue
+
     top = os.path.realpath(target)
-    proc_mounts = open('/proc/mounts', 'r')
+    try:
+        proc_mounts = open('/proc/mounts', 'r')
+    except IOError:
+        print >> sys.stdout, 'Cannot open /proc/mounts!'
+        sys.exit(1)
+
     for line in proc_mounts:
-        _, point, _ = line.split(' ', 2)
+        _, point, fstype, _ = line.split(' ', 3)
         point = mntent_unescape(point)
         if top == point or os.path.commonprefix((top + '/', point)) == top + '/':
-            if subprocess.call(['umount', point]) != 0:
-                exit_status = 1
+            if fstype.startswith('fuse'):
+                if subprocess.call(['fusermount', '-uz', point]) != 0:
+                    exit_status = 1
+            else:
+                if subprocess.call(['umount', '-l', point]) != 0:
+                    exit_status = 1
 
 sys.exit(exit_status)