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.

Author eryksun
Recipients benrg, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2022-02-26.05:08:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645852128.15.0.694486960128.issue46858@roundup.psfhosted.org>
In-reply-to
Content
The resize() method also modifies the file pointer. Instead of fixing that oversight, I think it should directly set the file's FileEndOfFileInfo and FileAllocationInfo. For example:

            // resize the file
            if (!SetFileInformationByHandle(
                    self->file_handle, FileEndOfFileInfo,
                    &max_size, sizeof(max_size)) ||
                  !SetFileInformationByHandle(
                        self->file_handle, FileAllocationInfo,
                        &max_size, sizeof(max_size)))
            {
                // resizing failed. try to remap the file
                file_resize_error = GetLastError();
                max_size.QuadPart = self->size;
                new_size = self->size;
            }

This is cheaper in terms of system calls. The existing implementation makes four system calls: one to set the file pointer in SetFilePointerEx() and three in SetEndOfFile(), which queries the file pointer, sets the end-of-file info, and sets the allocation info. 

Note that this approach doesn't modify the file pointer in any case. This may be surprising if the file size shrinks to less than the existing file pointer. But os.ftruncate() behaves the same way, as does the resize() method in Linux.
History
Date User Action Args
2022-02-26 05:08:48eryksunsetrecipients: + eryksun, paul.moore, tim.golden, benrg, zach.ware, steve.dower
2022-02-26 05:08:48eryksunsetmessageid: <1645852128.15.0.694486960128.issue46858@roundup.psfhosted.org>
2022-02-26 05:08:48eryksunlinkissue46858 messages
2022-02-26 05:08:48eryksuncreate