summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2023-01-09 15:30:38 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2023-01-09 15:30:38 +0100
commit2da99502238852f18f74db05304e67a01ee77005 (patch)
tree4bc44cd976a9ad90c877a008190e538124d18e69
parentc6b71453653609827f74aa074989ae4b9da69ece (diff)
downloadpsutil-2da99502238852f18f74db05304e67a01ee77005.tar.gz
#2191 / disk_partitions(): if all=True, do not unnecessarily list disk partitions
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r--psutil/_pslinux.py21
1 files 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'):