resize_file
has impossible postconditionSection: 31.12.13.34 [fs.op.resize.file] Status: C++20 Submitter: Richard Smith Opened: 2016-11-07 Last modified: 2021-06-06
Priority: 3
View all issues with C++20 status.
Discussion:
resize_file
has this postcondition (after resolving late comment 42, see P0489R0):
Postcondition:
file_size(p) == new_size
.
This is impossible for an implementation to satisfy, due to the possibility of file system races. This is not actually a postcondition; rather, it is an effect that need no longer hold when the function returns.
[Issues Telecon 16-Dec-2016]
Priority 3
[2018-01-16, Jonathan provides wording]
[2018-1-26 issues processing telecon]
Status to 'Tentatively Ready'
[2018-3-17 Adopted in Jacksonville]
Proposed resolution:
This wording is relative to N4713.
[Drafting note: I considered a slightly more verbose form: "Causes the size in bytes of the file
p
resolves to, as determined byfile_size
( [fs.op.file_size]), to be equal tonew_size
, as if by POSIXtruncate
." but I don't think it's an improvement. The intent of the proposed wording is that if eitherfile_size(p)
ortruncate(p.c_str())
would fail then an error occurs, but no call tofile_size
is required, and file system races might change the size before any such call does occur.]
Modify [fs.op.resize_file] as indicated:
void resize_file(const path& p, uintmax_t new_size); void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;-1-
-2- Throws: As specified in 31.12.5 [fs.err.report].Postconditions:Effects: Causes the size that would be returned byfile_size(p) == new_size
file_size(p)
to be equal tonew_size
, as if by POSIXtruncate
.-3- Remarks: Achieves its postconditions as if by POSIXtruncate()
.