Skip to content

Fix truncation when overwriting in-memory files - #431

Open
rksharma-owg wants to merge 1 commit into
google:mainfrom
rksharma-owg:fix/truncate-memory-file-overwrites
Open

rksharma-owg wants to merge 1 commit into
google:mainfrom
rksharma-owg:fix/truncate-memory-file-overwrites

Conversation

@rksharma-owg

Copy link
Copy Markdown

Opening an existing MemoryFileSystem file with w or wb currently retains its old buffer contents. Writing "hello", reopening with w, and writing "x" yields "xello"; opening with w without writing leaves the entire old file intact.

Reset the file position and truncate the buffer on write-mode open, updating modification time while preserving creation time. Tests cover shorter and empty replacements for both text and binary files.

This is separate from #429, which addresses path-prefix stripping.

Validation on macOS, Python 3.12.13:

  • Both new regression cases fail before the fix.
  • I/O tests: 32 passed, 2 subtests passed.
  • Full suite excluding the separately run reloader tests: 1720 passed, 1 skipped, 2 subtests passed.
  • Reloader tests: 4 passed.
  • git diff --check passes.

AI assistance: Codex assisted with investigation, implementation, and local verification.

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.

1 participant