diff --git a/src/bun.js/webcore/S3File.zig b/src/bun.js/webcore/S3File.zig index 08f061eabf..9ce9d2363d 100644 --- a/src/bun.js/webcore/S3File.zig +++ b/src/bun.js/webcore/S3File.zig @@ -148,7 +148,7 @@ pub fn write(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSE .path => |path| { const options = args.nextEat(); var mode: ?u32 = null; - + // Parse mode from options if present if (options) |options_object| { if (options_object.isObject()) { @@ -159,7 +159,7 @@ pub fn write(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSE } } } - + if (path == .fd) { return globalThis.throwInvalidArguments("Expected a S3 or path to upload", .{}); } @@ -176,7 +176,7 @@ pub fn write(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSE .blob => { const options = args.nextEat(); var mode: ?u32 = null; - + // Parse mode from options if present if (options) |options_object| { if (options_object.isObject()) { @@ -187,7 +187,7 @@ pub fn write(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSE } } } - + return try Blob.writeFileInternal(globalThis, &path_or_blob, data, .{ .mkdirp_if_not_exists = false, .extra_options = options, diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index cbcafd91f5..85296324c1 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -533,12 +533,12 @@ if (!isWindows) { describe("mode option", () => { it("Bun.write() with mode option sets correct file permissions", async () => { const filename = path.join(tmpdir(), `mode-test-${Date.now()}.txt`); - + // Test mode 0o644 (read/write for owner, read for group/others) await Bun.write(filename, "test content", { mode: 0o644 }); const stats = fs.statSync(filename); expect(stats.mode & 0o777).toBe(0o644); - + try { fs.unlinkSync(filename); } catch (e) {} @@ -546,12 +546,12 @@ if (!isWindows) { it("Bun.write() with mode option as decimal", async () => { const filename = path.join(tmpdir(), `mode-decimal-test-${Date.now()}.txt`); - + // Test mode 0o755 as decimal (493) await Bun.write(filename, "test content", { mode: 493 }); const stats = fs.statSync(filename); expect(stats.mode & 0o777).toBe(0o755); - + try { fs.unlinkSync(filename); } catch (e) {} @@ -560,12 +560,12 @@ if (!isWindows) { it("Bun.write() with mode option and createPath", async () => { const testDir = path.join(tmpdir(), `mode-mkdir-test-${Date.now()}`); const filename = path.join(testDir, "test.txt"); - + // Test mode with createPath await Bun.write(filename, "test content", { mode: 0o600, createPath: true }); const stats = fs.statSync(filename); expect(stats.mode & 0o777).toBe(0o600); - + try { fs.rmSync(testDir, { recursive: true }); } catch (e) {} @@ -574,12 +574,12 @@ if (!isWindows) { it("blob.write() with mode option", async () => { const filename = path.join(tmpdir(), `blob-mode-test-${Date.now()}.txt`); const file = Bun.file(filename); - + // Test blob write with mode await file.write("test content", { mode: 0o640 }); const stats = fs.statSync(filename); expect(stats.mode & 0o777).toBe(0o640); - + try { fs.unlinkSync(filename); } catch (e) {} @@ -588,15 +588,15 @@ if (!isWindows) { it("Bun.write() file to file copy with mode", async () => { const sourceFile = path.join(tmpdir(), `source-${Date.now()}.txt`); const destFile = path.join(tmpdir(), `dest-mode-${Date.now()}.txt`); - + // Create source file await Bun.write(sourceFile, "source content"); - + // Copy with specific mode await Bun.write(Bun.file(destFile), Bun.file(sourceFile), { mode: 0o660 }); const stats = fs.statSync(destFile); expect(stats.mode & 0o777).toBe(0o660); - + try { fs.unlinkSync(sourceFile); fs.unlinkSync(destFile); @@ -606,12 +606,12 @@ if (!isWindows) { it("mode validation - should handle edge cases", async () => { const filename1 = path.join(tmpdir(), `mode-truncate-test-${Date.now()}.txt`); const filename2 = path.join(tmpdir(), `mode-negative-test-${Date.now()}.txt`); - + // Test mode > 0o777 gets truncated (like Node.js) await Bun.write(filename1, "test", { mode: 0o1644 }); const stats1 = fs.statSync(filename1); expect(stats1.mode & 0o777).toBe(0o644); // 0o1644 & 0o777 = 0o644 - + // Test negative mode should throw try { await Bun.write(filename2, "test", { mode: -1 }); @@ -619,7 +619,7 @@ if (!isWindows) { } catch (error) { expect(error.message).toContain("out of range"); } - + try { fs.unlinkSync(filename1); } catch (e) {} @@ -634,11 +634,11 @@ if (!isWindows) { for (const [type, data] of testCases) { const filename = path.join(tmpdir(), `mode-${type}-test-${Date.now()}.txt`); - + await Bun.write(filename, data, { mode: 0o622 }); const stats = fs.statSync(filename); expect(stats.mode & 0o777).toBe(0o622); - + try { fs.unlinkSync(filename); } catch (e) {}