commit: cbd0a3effad6a0e1dd6ce025f94b13bdb3b6472a Author: Matt Turner <mattst88 <AT> gentoo <DOT> org> AuthorDate: Thu Oct 22 18:52:46 2020 +0000 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org> CommitDate: Thu Oct 22 18:57:25 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=cbd0a3ef
catalyst: Rewrite ismount() to use libmount Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org> catalyst/support.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/catalyst/support.py b/catalyst/support.py index f49315a5..00a95006 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -5,8 +5,11 @@ import os import re import shutil import time +from pathlib import Path from subprocess import Popen +import libmount + from catalyst import log BASH_BINARY = "/bin/bash" @@ -179,31 +182,17 @@ def read_makeconf(mymakeconffile): return makeconf -def pathcompare(path1, path2): - # Change double slashes to slash - path1 = re.sub(r"//", r"/", path1) - path2 = re.sub(r"//", r"/", path2) - # Removing ending slash - path1 = re.sub("/$", "", path1) - path2 = re.sub("/$", "", path2) - - if path1 == path2: - return 1 - return 0 - - def ismount(path): """Like os.path.ismount, but also support bind mounts""" if os.path.ismount(path): - return 1 - a = os.popen("mount") - mylines = a.readlines() - a.close() - for line in mylines: - mysplit = line.split() - if pathcompare(path, mysplit[2]): - return 1 - return 0 + return True + + cxt = libmount.Context() + while (fs := cxt.mtab.next_fs()) is not None: + if Path(path) == Path(fs.source): + return True + + return False def addl_arg_parse(myspec, addlargs, requiredspec, validspec):