Repository navigation
Preserve manifest input streams when writing manifests - #14883
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Tasks/ManifestUtil/Util.cs — WriteFile(string, Stream) now uses leaveOpen: true, so it no longer disposes the… |
What changed in this PR
This PR fixes a regression in the manifest utilities where writing a manifest could dispose the manifest’s preserved (caller-owned) input stream, breaking subsequent reuse of the same Manifest instance.
Changes:
- Update
Util.WriteFile(string, Stream)to construct aStreamReaderwithleaveOpen: trueso disposing the reader doesn’t close the supplied stream. - Add a regression unit test that writes the same manifest twice after rewinding its preserved input stream and verifies both outputs match and the input stream remains readable.
| File | Description |
|---|---|
| src/Tasks/ManifestUtil/Util.cs | Preserves caller-owned streams by leaving the input stream open when reading it via StreamReader. |
| src/Tasks.UnitTests/ManifestWriter_Tests.cs | Adds regression coverage to ensure ManifestWriter.WriteManifest doesn’t dispose preserved input streams and that repeated writes are consistent. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
VolPlita
left a comment
There was a problem hiding this comment.
One thought: the stream remains positioned at EOF, so callers still need to rewind it before another write. This matches the issue’s expected usage, but documenting this contract would help prevent future cleanup from reintroducing the bug.
|
The stream does remain at EOF after writing, and callers must rewind it before reusing it. However, that is separate from the regression fixed here: PR #9983 introduced disposal of a stream that this path did not own. I checked the analogous fixes made during #9983 itself. |

Fixes #14881.
Summary
Ensure
ManifestWriter.WriteManifestleaves the manifest's caller-owned input stream open after writing.PR #9983 began disposing the
StreamReader, which also disposed the underlying manifest input stream. This caused subsequent calls toManifestWriter.WriteManifestusing the same manifest to fail withStream was not readable.The explicit
StreamReaderarguments preserve the previous encoding, BOM detection, and buffer-size behavior while settingleaveOpen: true.Compatibility
This restores the stream-ownership behavior from before PR #9983. No ChangeWave is needed because this is a narrow regression fix and does not change the public API surface.
Tests
Added regression coverage that:
The regression test passes on both
net11.0andnet472.