[issue32557] allow shutil.disk_usage to take a file path on Windows also

Steve Dower report at bugs.python.org
Wed Sep 19 19:12:36 EDT 2018


Steve Dower <steve.dower at python.org> added the comment:

(Excuse the GitHub syntax - was about to post it there, but it got long enough to belong here)

Regarding the `_dirnameW` discussion, fixing `_dirname` would be ideal, but that is bloating out your PR quite a bit :)

The "right" function to use there is [PathCchRemoveFileSpec](https://docs.microsoft.com/en-us/windows/desktop/api/pathcch/nf-pathcch-pathcchremovefilespec), which unfortunately does not exist on Windows 7.

The fallback is [PathRemoveFileSpec](https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathremovefilespeca) which only supports up to `MAX_PATH` (but may do something relatively sensible for longer paths, such as trimming out the last directory separator before that limit - I haven't tested it).

Supporting both is tricky - there's a similar example in `PC/getpathp.c` for `PathCchCombineEx` that could be replicated for dirname. But I'd be okay with taking this PR without that fix and filing a new bug for `_dirnameW`.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32557>
_______________________________________


More information about the Python-bugs-list mailing list