This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Report actual size from 'os.path.getsize'
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gdr@garethrees.org, stephenfin
Priority: normal Keywords: patch

Created on 2020-06-23 16:44 by stephenfin, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21088 open stephenfin, 2020-06-23 16:53
Messages (2)
msg372183 - (view) Author: Stephen Finucane (stephenfin) * Date: 2020-06-23 16:44
The 'os.path.getsize' API returns the apparent size of the file at *path*, that is, the number of bytes the file reports itself as consuming. However, it's often useful to get the actual size of the file, or the size of file on disk. It would be helpful if one could get this same information from 'os.path.getsize'.
msg372412 - (view) Author: Gareth Rees (gdr@garethrees.org) * (Python triager) Date: 2020-06-26 07:03
The proposed change adds a Boolean flag to os.path.getsize() so that it returns:

    os.stat(filename).st_blocks * 512

(where the 512 is the file system block size on Linux; some work is needed to make this portable to other operating systems).

The Boolean argument here would always be constant in practice -- that is, you'd always call it like this:

    virtual_size = os.path.getsize(filename, apparent=True)
    allocated_size = os.path.getsize(filename, apparent=False)

and never like this:

    x_size = os.path.getsize(filename, apparent=x)

where x varies at runtime.

The "no constant bool arguments" design principle [1] suggests that this should be added as a new function, something like os.path.getallocatedsize().

  [1] https://mail.python.org/pipermail/python-ideas/2016-May/040181.html
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85264
2020-06-26 07:03:47gdr@garethrees.orgsetnosy: + gdr@garethrees.org
messages: + msg372412
2020-06-23 16:53:38stephenfinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20254
2020-06-23 16:44:46stephenfincreate