pjfanning opened a new pull request, #1523: URL: https://github.com/apache/poi/pull/1523
Follow-up to #1520. A `POIFSFileSystem` opened read-only from a file (`new POIFSFileSystem(file)` and `new POIFSFileSystem(file, true)`) reads each block into a heap copy. So: - stream data written to it (`createDocument`, `createOrUpdateDocument`, `DocumentOutputStream`) was lost straight away, and reading it back gave the old contents; - `writeFilesystem(OutputStream)` synced into those copies and then copied the original file, so any changes were dropped, and the data of deleted streams that #1520 now clears was still written out. All of this happened without any error. Changes: - Writing stream data to a read-only file now throws an `IllegalStateException`, checked before the old contents are freed so the in-memory tree is left intact (`POIFSStream` output, `POIFSDocument.replaceContents`, `DocumentOutputStream`). This goes through a new `BlockStore.checkWriteable()` hook, which `POIFSMiniStore` delegates to the file system. - Changes to the entries (delete, rename, new directories, storage CLSIDs) still work in memory, so code that edits the tree and copies it elsewhere, e.g. with `EntryUtils.copyNodes`, keeps working. `writeFilesystem(OutputStream)` now throws if there were any such changes, instead of writing stale output. - An unchanged read-only file system skips the sync, which went into the block copies and was dropped anyway, and is written out byte for byte as before. - Test tidy-up from #1520: messages on the boolean assertions, and no assertion in the `finally` block. `TestPOIFSStream.readOnlyFileChangesAreNotLost` covers the new behaviour. The existing `RecursiveDelete` test, which deletes from a read-only file in memory, still passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
