Copy files with bounded memory through File by snowyukitty · Pull Request #806 · rbfx/rbfx · GitHub
Skip to content

Copy files with bounded memory through File - #806

Open
snowyukitty wants to merge 2 commits into
rbfx:masterfrom
snowyukitty:fix/bounded-file-copy
Open

snowyukitty wants to merge 2 commits into
rbfx:masterfrom
snowyukitty:fix/bounded-file-copy

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Oct 11, 2026 •

Copy link
Copy Markdown

Addresses the whole-file allocation in #798.

Stream through the existing File::Copy API using a reusable buffer of at most 64 KiB, and let FileSystem::Copy delegate to it. Both existing APIs avoid a whole-file allocation. File opening, native handles, asset handling and flush error checking stay inside File; FileSystem keeps its access checks.

Check each read and write, and report a buffered-write flush failure before returning success. Preserve overwrite/truncation, Unicode paths, empty files and missing-source behavior. The existing File size limits remain unchanged; this patch does not add a 64-bit file API or support for files above that limit.

Native regressions cover both entry points, buffer boundaries, Unicode paths, overwrite/truncation, empty files, missing sources, access restrictions and Linux buffered-write failures. A separate hidden [large-file] test copies 2 GiB + 65,537 bytes and compares every byte; run it explicitly with Tests "[large-file]". It reports that the regression was not run on platforms whose signed-long offsets cannot represent the file.

Validation on Linux: 188 ordinary native cases pass, plus the large-file case under a 1 GiB virtual-memory limit. Restoring the original File::Copy reproduces buffered-output failures and allocation failure in the large copy. The build uses GCC 12 and a reduced feature set. Windows, macOS and Android were not run locally.

Comment thread Source/Urho3D/IO/FileSystem.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this seems largely unnecessary. All you had to do is to add a loop around reading/writing calls using our File and reduce size of buffer. This code duplicates platform-specific functionality that File is meant to abstract.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. FileSystem::Copy has no place for platform-specific code.

@snowyukitty snowyukitty changed the title Copy files with bounded memory and 64-bit sizes Copy files with bounded memory through File Oct 15, 2026
@snowyukitty

Copy link
Copy Markdown
Author

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants