Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/runtime/webcore/FileSink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,12 @@ impl FileSink {

pub fn start(&self, stream_start: streams::Start) -> sys::Result<()> {
match stream_start {
streams::Start::FileSink(ref file) => {
streams::Start::FileSink(ref file)
if !matches!(
file.input_path,
crate::webcore::PathOrFileDescriptor::Fd(Fd::INVALID)
) =>
{
// PORT NOTE: `streams::FileSinkOptions` mirrors `file_sink::Options`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

They should use the same options type? Can you also change that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 42d8725 — streams::FileSinkOptions is now a type alias for file_sink::Options, so start() passes the options straight to setup() without the bridge.

// but is a distinct draft type; bridge by-field until streams.rs
// aliases to this module's `Options`.
Expand Down
10 changes: 10 additions & 0 deletions test/js/bun/util/filesink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,13 @@ it.skipIf(!isPosix)("does not leak native FileSink when a pending write fails (E
// more than that indicates a native leak.
expect(fileSinkInternals.liveCount()).toBeLessThanOrEqual(baseline + 1);
});

it("start() without path/fd on an already-open writer does not crash", async () => {
const path = join(tmpdirSync(), "filesink-restart.txt");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const writer = Bun.file(path).writer();
expect(() => writer.start({})).not.toThrow();
expect(() => writer.start({ highWaterMark: 1024 })).not.toThrow();
writer.write("hello");
await writer.end();
expect(await Bun.file(path).text()).toBe("hello");
});
Loading