From 38a65f9eb34f59519e2e9db362106a5f3b094c3b Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 12 Feb 2016 09:45:47 +0100 Subject: [PATCH] in case there are multiple mounts for same path, prefer REAL_FILESYSTEM_TYPE --- src/file_helpers.py | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/file_helpers.py b/src/file_helpers.py index fe89e05..8ad76f4 100644 --- a/src/file_helpers.py +++ b/src/file_helpers.py @@ -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): -- 1.7.1