From b46bcaa4af311a9ef29775df183348dc166cb361 Mon Sep 17 00:00:00 2001 From: Christophe Varoqui Date: Wed, 12 Feb 2020 07:17:43 +0100 Subject: [PATCH] Fix a stack sorting fs.dir and fs.flag resources in the same object Catch AttributeError from resFs __lt__ when comparing mount_point attrs, as this attribute may not exist in all fs drivers (ex: fs.flag). Resync the resFsDir __lt__ definition from resFs. Do not return the first fs resource mount point as the volume mount point, as the first fs resource might not have a mount_point attribute. Return the mount point of the first fs resource with a mount_point attribute instead. --- lib/resFs.py | 7 +++++-- lib/resFsDir.py | 14 ++++++++------ lib/svc.py | 6 +++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/resFs.py b/lib/resFs.py index 3718a454cc..418587e05b 100644 --- a/lib/resFs.py +++ b/lib/resFs.py @@ -236,8 +236,11 @@ def __lt__(self, other): Order so that deepest mountpoint can be umount first. If no ordering constraint, honor the rid order. """ - smnt = os.path.dirname(self.mount_point) - omnt = os.path.dirname(other.mount_point) + try: + smnt = os.path.dirname(self.mount_point) + omnt = os.path.dirname(other.mount_point) + except AttributeError: + return self.rid < other.rid return (smnt, self.rid) < (omnt, other.rid) @lazy diff --git a/lib/resFsDir.py b/lib/resFsDir.py index 7e1fa693a7..5cecf98e01 100644 --- a/lib/resFsDir.py +++ b/lib/resFsDir.py @@ -125,10 +125,12 @@ def __str__(self): def __lt__(self, other): """ - Order so that deepest mountpoint can be umount first + Order so that deepest mountpoint can be umount first. + If no ordering constraint, honor the rid order. """ - return self.mount_point < other.mount_point - - - - + try: + smnt = os.path.dirname(self.mount_point) + omnt = os.path.dirname(other.mount_point) + except AttributeError: + return self.rid < other.rid + return (smnt, self.rid) < (omnt, other.rid) diff --git a/lib/svc.py b/lib/svc.py index b305c12714..84c03a1a09 100644 --- a/lib/svc.py +++ b/lib/svc.py @@ -5612,7 +5612,11 @@ def mount_point(self): candidates = [res for res in self.get_resources("fs")] if not candidates: return - return sorted(candidates)[0].mount_point + for candidate in sorted(candidates): + if not hasattr(candidate, "mount_point"): + continue + return candidate.mount_point + raise IndexError def device(self): """