classification
Title: allow shutil.disk_usage to take a file path on Windows also
Type: enhancement Stage: needs patch
Components: Library (Lib), Windows Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, giampaolo.rodola, paul.moore, steve.dower, terry.reedy, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-01-15 15:26 by eryksun, last changed 2018-06-12 09:39 by giampaolo.rodola.

Messages (3)
msg309992 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-01-15 15:26
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.
msg310286 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-01-19 20:04
Seems sensible to me.
msg319371 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2018-06-12 09:39
+1
History
Date User Action Args
2018-06-12 09:39:41giampaolo.rodolasetnosy: + giampaolo.rodola
messages: + msg319371
2018-01-19 20:04:41terry.reedysetnosy: + terry.reedy

messages: + msg310286
title: allow shutil.disk_usage to take a file path -> allow shutil.disk_usage to take a file path on Windows also
2018-01-15 15:26:52eryksuncreate