From 70f8b813f92f97db277e05a9843da4761eef8528 Mon Sep 17 00:00:00 2001 From: Zack Radisic Date: Thu, 11 Apr 2024 09:32:33 -0700 Subject: [PATCH] Make it work on windows --- src/bun.js/node/node_fs.zig | 6 +++++- src/shell/interpreter.zig | 1 + test/js/bun/shell/commands/cp.test.ts | 11 +++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 71560f4579ec7..306bd79f847fd 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -248,6 +248,7 @@ pub const AsyncCPTaskVtable = struct { onCopy: *const (fn (*anyopaque, [:0]const u8, [:0]const u8) void) = undefined, onFinish: *const (fn (*anyopaque, Maybe(void)) void) = undefined, is_shell: bool = true, + verbose: bool = false, pub const Dead = AsyncCPTaskVtable{ .ctx = @ptrFromInt(0xDEADBEEF), @@ -280,6 +281,7 @@ pub const AsyncCPTaskVtable = struct { .onCopy = wrapOnCopy, .onFinish = wrapOnFinish, .ctx = ctx, + .verbose = Type.verbose, }; } @@ -328,9 +330,11 @@ pub const AsyncCpTask = struct { pub fn onCopy(this: *AsyncCpTask, src_: anytype, dest_: anytype) void { if (@intFromPtr(this.vtable.ctx) == @intFromPtr(AsyncCPTaskVtable.Dead.ctx)) return; + if (!this.vtable.verbose) return; if (comptime bun.Environment.isPosix) return this.vtable.onCopy(this.vtable.ctx, src_, dest_); var buf: bun.PathBuffer = undefined; + var buf2: bun.PathBuffer = undefined; const src: [:0]const u8 = switch (@TypeOf(src_)) { [:0]const u8, [:0]u8 => src_, [:0]const u16, [:0]u16 => bun.strings.fromWPath(buf[0..], src_), @@ -338,7 +342,7 @@ pub const AsyncCpTask = struct { }; const dest: [:0]const u8 = switch (@TypeOf(dest_)) { [:0]const u8, [:0]u8 => src_, - [:0]const u16, [:0]u16 => bun.strings.fromWPath(buf[0..], dest_), + [:0]const u16, [:0]u16 => bun.strings.fromWPath(buf2[0..], dest_), else => @compileError("Invalid type: " ++ @typeName(@TypeOf(dest_))), }; diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index f299cd1071016..cbfe7cd5ef195 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -10576,6 +10576,7 @@ pub const Interpreter = struct { } const NodeCpVtable = struct { + pub const verbose = true; inline fn shellTask(this: *NodeCpVtable) *ShellCpTask { return @fieldParentPtr(ShellCpTask, "vtable", this); } diff --git a/test/js/bun/shell/commands/cp.test.ts b/test/js/bun/shell/commands/cp.test.ts index f85123faa9cea..28c953b91195a 100644 --- a/test/js/bun/shell/commands/cp.test.ts +++ b/test/js/bun/shell/commands/cp.test.ts @@ -7,22 +7,25 @@ import fs from "fs"; import { shellInternals } from "bun:internal-for-testing"; const { builtinDisabled } = shellInternals +const p = process.platform === 'win32' ? (s: string) => s.replaceAll('/', '\\') : (s: string) => s; +// const p = (s: string) => s; + describe.if(!builtinDisabled("cp"))("bunshell cp", async () => { TestBuilder.command`cat ${import.meta.filename} > lmao.txt; cp -v lmao.txt lmao2.txt` - .stdout("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2.txt\n") + .stdout(p("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2.txt\n")) .ensureTempDir() .fileEquals("lmao2.txt", await $`cat ${import.meta.filename}`.text()) .runAsTest("file -> file"); TestBuilder.command`cat ${import.meta.filename} > lmao.txt; touch lmao2.txt; cp -v lmao.txt lmao2.txt` - .stdout("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2.txt\n") + .stdout(p("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2.txt\n")) .ensureTempDir() .fileEquals("lmao2.txt", await $`cat ${import.meta.filename}`.text()) .runAsTest("file -> existing file replaces contents"); TestBuilder.command`cat ${import.meta.filename} > lmao.txt; mkdir lmao2; cp -v lmao.txt lmao2` .ensureTempDir() - .stdout("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2/lmao.txt\n") + .stdout(p("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao2/lmao.txt\n")) .fileEquals("lmao2/lmao.txt", await $`cat ${import.meta.filename}`.text()) .runAsTest("file -> dir"); @@ -36,7 +39,7 @@ describe.if(!builtinDisabled("cp"))("bunshell cp", async () => { .ensureTempDir() .stdout( expectSortedOutput( - "$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao3/lmao.txt\n$TEMP_DIR/lmao2.txt -> $TEMP_DIR/lmao3/lmao2.txt\n", + p("$TEMP_DIR/lmao.txt -> $TEMP_DIR/lmao3/lmao.txt\n$TEMP_DIR/lmao2.txt -> $TEMP_DIR/lmao3/lmao2.txt\n"), ), ) .fileEquals("lmao3/lmao.txt", await $`cat ${import.meta.filename}`.text())