From 2da99502238852f18f74db05304e67a01ee77005 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 9 Jan 2023 15:30:38 +0100 Subject: #2191 / disk_partitions(): if all=True, do not unnecessarily list disk partitions Signed-off-by: Giampaolo Rodola --- psutil/_pslinux.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 9dc9643a..33ee1b14 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1257,16 +1257,17 @@ def disk_partitions(all=False): """Return mounted disk partitions as a list of namedtuples.""" fstypes = set() procfs_path = get_procfs_path() - with open_text("%s/filesystems" % procfs_path) as f: - for line in f: - line = line.strip() - if not line.startswith("nodev"): - fstypes.add(line.strip()) - else: - # ignore all lines starting with "nodev" except "nodev zfs" - fstype = line.split("\t")[1] - if fstype == "zfs": - fstypes.add("zfs") + if not all: + with open_text("%s/filesystems" % procfs_path) as f: + for line in f: + line = line.strip() + if not line.startswith("nodev"): + fstypes.add(line.strip()) + else: + # ignore all lines starting with "nodev" except "nodev zfs" + fstype = line.split("\t")[1] + if fstype == "zfs": + fstypes.add("zfs") # See: https://github.com/giampaolo/psutil/issues/1307 if procfs_path == "/proc" and os.path.isfile('/etc/mtab'): -- cgit v1.2.1