Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test-fs-promises-writefile.js on windows #17053

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/io/PipeWriter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,11 @@ fn BaseWindowsPipeWriter(
.sync_file, .file => |file| {
// always cancel the current one
file.fs.cancel();
// always use close_fs here because we can have a operation in progress
file.close_fs.data = file;
_ = uv.uv_fs_close(uv.Loop.get(), &file.close_fs, file.file, onFileClose);
if (this.owns_fd) {
// always use close_fs here because we can have a operation in progress
file.close_fs.data = file;
_ = uv.uv_fs_close(uv.Loop.get(), &file.close_fs, file.file, onFileClose);
}
},
.pipe => |pipe| {
pipe.data = pipe;
Expand Down Expand Up @@ -1044,7 +1046,6 @@ pub fn WindowsBufferedWriter(
this.is_done = true;
if (this.pending_payload_size == 0) {
// will auto close when pending stuff get written
if (!this.owns_fd) return;
this.close();
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/js/bun/util/bun-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from "bun:test";
import { tmpdirSync } from "harness";
import { join } from "path";
import fsPromises from "fs/promises";

test("delete() and stat() should work with unicode paths", async () => {
const testDir = tmpdirSync();
Expand All @@ -21,3 +22,17 @@ test("delete() and stat() should work with unicode paths", async () => {

expect(await Bun.file(filename).exists()).toBe(false);
});

test("writer.end() should not close the fd if it does not own the fd", async () => {
const testDir = tmpdirSync();
for (let i = 0; i < 30; i++) {
const fileHandle = await fsPromises.open(testDir + "/tmp.txt", "w", 0o666);
const fd = fileHandle.fd;

await Bun.file(fd).writer().end();
// @ts-ignore
await fsPromises.close(fd);
expect(await Bun.file(testDir + "/tmp.txt").text()).toBe("");
await Bun.sleep(50);
}
});