Skip to content

Commit

Permalink
#2191 / disk_partitions(): if all=True, do not unnecessarily list dis…
Browse files Browse the repository at this point in the history
…k partitions

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
  • Loading branch information
giampaolo committed Jan 9, 2023
1 parent c6b7145 commit 2da9950
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down

0 comments on commit 2da9950

Please sign in to comment.