in case there are multiple mounts for same path, prefer REAL_FILESYSTEM_TYPE
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 12 Feb 2016 08:45:47 +0000 (09:45 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 12 Feb 2016 08:45:47 +0000 (09:45 +0100)
src/file_helpers.py

index fe89e05..8ad76f4 100644 (file)
@@ -384,6 +384,8 @@ def get_mount_info(path):
 
     mount_point = find_mount_point(path)
 
+    candidates = []
+
     with open('/proc/mounts', 'rt') as file_handle:
         for line in file_handle:
             parts = line.split()
@@ -396,9 +398,25 @@ def get_mount_info(path):
             new_mount = MountPoint()
             for field_name, value in matches.groupdict().items():
                 setattr(new_mount, field_name, value)
-            return new_mount
+            candidates.append(new_mount)
+
+    if not candidates:
+        raise NotImplementedError('impossible: mount point not found in '
+                                  'fstab!')
+    elif len(candidates) == 1:
+        return candidates[0]
+
+    # decide which candidates to use: return first that is a "real"
+    # filesystem (e.g. prefer ext4 before rootfs for '/')
+    for candidate in candidates:
+        print(candidate.vfstype)
+        if candidate.vfstype in REAL_FILESYSTEMS_TYPE and \
+                candidate.spec not in NOT_REAL_FILESYSTEMS_SPEC:
+            return candidate
+
+    # otherwise just return first
+    return candidates[0]
 
-    raise NotImplementedError('impossible: mount point not found in fstab!')
 
 
 def find_mount_point(path):