[New-bugs-announce] [issue32557] allow shutil.disk_usage to take a file path
Eryk Sun
report at bugs.python.org
Mon Jan 15 10:26:52 EST 2018
New submission from Eryk Sun <eryksun at gmail.com>:
Issue 26330 was resolved by documenting that shutil.disk_usage requires a directory. However, the shutil module is in a position to harmonize cross-platform behavior in ways that aren't normally possible or recommended in the low-level os module. To that end, the Windows implementation could retry calling nt._getdiskusage on the resolved parent directory in case of NotADirectoryError. For example:
def disk_usage(path):
try:
total, free = nt._getdiskusage(path)
except NotADirectoryError:
path = os.path.dirname(nt._getfinalpathname(path))
total, free = nt._getdiskusage(path)
used = total - free
return _ntuple_diskusage(total, used, free)
Alternatively, this could be addressed in the implementation of nt._getdiskusage itself.
----------
components: Library (Lib), Windows
messages: 309992
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
stage: needs patch
status: open
title: allow shutil.disk_usage to take a file path
type: enhancement
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32557>
_______________________________________
More information about the New-bugs-announce
mailing list