Gentoo Archives: gentoo-catalyst

From: Matt Turner <mattst88@g.o>
To: gentoo-catalyst@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-catalyst] [PATCH 02/12] catalyst: Rewrite ismount() to use libmount
Date: Thu, 29 Oct 2020 16:16:41
Message-Id: 20201029161632.146732-2-mattst88@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 01/12] catalyst: Replace pathcompare() by Matt Turner
1 libmount is provided by util-linux, so this adds a dependency on
2 sys-apps/util-linux[python]. A later patch will make more extensive use
3 of this API.
4
5 Signed-off-by: Matt Turner <mattst88@g.o>
6 ---
7 README | 2 +-
8 catalyst/support.py | 14 +++++++-------
9 2 files changed, 8 insertions(+), 8 deletions(-)
10
11 diff --git a/README b/README
12 index 1cceb63e..594de9e1 100644
13 --- a/README
14 +++ b/README
15 @@ -17,7 +17,7 @@ simple and reproducable manner. Use at your own risk.
16 Requirements
17 =======================
18
19 -- Python 3.6 or greater
20 +- Python 3.8 or greater
21 - A generic stage3 tarball for your architecture
22 - A squashfs ebuild repository snapshot
23 - Or an ebuild git repo with sys-fs/squashfs-tools-ng and dev-vcs/git
24 diff --git a/catalyst/support.py b/catalyst/support.py
25 index 4458ed20..ddbd9ab9 100644
26 --- a/catalyst/support.py
27 +++ b/catalyst/support.py
28 @@ -8,6 +8,8 @@ import time
29 from pathlib import Path
30 from subprocess import Popen
31
32 +import libmount
33 +
34 from catalyst import log
35
36 BASH_BINARY = "/bin/bash"
37 @@ -182,15 +184,13 @@ def read_makeconf(mymakeconffile):
38
39 def ismount(path):
40 """Like os.path.ismount, but also support bind mounts"""
41 - if os.path.ismount(path):
42 + path = Path(path)
43 + if path.is_mount():
44 return True
45
46 - a = os.popen("mount")
47 - mylines = a.readlines()
48 - a.close()
49 - for line in mylines:
50 - mysplit = line.split()
51 - if Path(path) == Path(mysplit[2]):
52 + cxt = libmount.Context()
53 + while (fs := cxt.mtab.next_fs()) is not None:
54 + if path == Path(fs.target):
55 return True
56
57 return False
58 --
59 2.26.2