mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
add .path support so we can use Bun.file as stdin/stdout/stderr
This commit is contained in:
@@ -3223,22 +3223,43 @@ pub const Subprocess = struct {
|
||||
.data = .{ .fd = bun.uvfdcast(_fd) },
|
||||
},
|
||||
.path => |pathlike| {
|
||||
_ = pathlike;
|
||||
@panic("TODO");
|
||||
// var file_path: [bun.MAX_PATH_BYTES]u8 = undefined;
|
||||
// const path_fd = try bun.sys.open(
|
||||
// pathlike.path.sliceZ(&file_path),
|
||||
// std.os.O.WRONLY | std.os.O.CREAT | std.os.O.NONBLOCK,
|
||||
// 0o664,
|
||||
// ).unwrap();
|
||||
var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
|
||||
var resolver = bun.path.PosixToWinNormalizer{};
|
||||
const flag: i32 = (if (isReadable) os.O.RDONLY else std.os.O.WRONLY);
|
||||
|
||||
// try pipe.init(uv.Loop.get(), false).unwrap();
|
||||
// try pipe.open(bun.uvfdcast(path_fd)).unwrap();
|
||||
var joined_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
|
||||
var slice = pathlike.sliceZ(&path_buf);
|
||||
if (!std.fs.path.isAbsoluteWindows(slice)) {
|
||||
// we need the absolute path so we can open
|
||||
var cwd_buf: [bun.MAX_PATH_BYTES + 1]u8 = undefined;
|
||||
|
||||
// return uv.uv_stdio_container_s{
|
||||
// .flags = @intCast(uv.UV_INHERIT_STREAM),
|
||||
// .data = .{ .stream = @ptrCast(pipe) },
|
||||
// };
|
||||
var parts = [_]string{
|
||||
slice,
|
||||
};
|
||||
|
||||
const application_cwd = try bun.getcwd(&cwd_buf);
|
||||
cwd_buf[application_cwd.len] = std.fs.path.sep;
|
||||
const file_path = bun.path.joinAbsStringBuf(
|
||||
cwd_buf[0 .. application_cwd.len + 1],
|
||||
&joined_buf,
|
||||
&parts,
|
||||
.auto,
|
||||
);
|
||||
|
||||
joined_buf[file_path.len] = 0;
|
||||
slice = joined_buf[0..file_path.len :0];
|
||||
}
|
||||
|
||||
const path_fd = try bun.sys.open(
|
||||
try resolver.resolveCWDZ(slice),
|
||||
flag | std.os.O.CREAT | std.os.O.NONBLOCK,
|
||||
0o664,
|
||||
).unwrap();
|
||||
|
||||
return uv.uv_stdio_container_s{
|
||||
.flags = uv.UV_INHERIT_FD,
|
||||
.data = .{ .fd = bun.uvfdcast(path_fd) },
|
||||
};
|
||||
},
|
||||
.inherit => uv.uv_stdio_container_s{
|
||||
.flags = uv.UV_INHERIT_FD,
|
||||
|
||||
Reference in New Issue
Block a user