From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 474331381F3 for ; Thu, 22 Oct 2020 18:59:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 890EEE0844; Thu, 22 Oct 2020 18:59:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6B5CCE0844 for ; Thu, 22 Oct 2020 18:59:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EA353335D8E for ; Thu, 22 Oct 2020 18:59:33 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 539AC33A for ; Thu, 22 Oct 2020 18:59:32 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1603393045.cbd0a3effad6a0e1dd6ce025f94b13bdb3b6472a.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/support.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: cbd0a3effad6a0e1dd6ce025f94b13bdb3b6472a X-VCS-Branch: pending/mattst88 Date: Thu, 22 Oct 2020 18:59:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 0aa56308-b235-460e-880d-91055ce7c5b1 X-Archives-Hash: e676a636b7d404bf75ccc70730eb4816 commit: cbd0a3effad6a0e1dd6ce025f94b13bdb3b6472a Author: Matt Turner gentoo org> AuthorDate: Thu Oct 22 18:52:46 2020 +0000 Commit: Matt Turner gentoo 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 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):