New submission from Eryk Sun <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue32557>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com