Skip to content

Commit 7240132

Browse files
committed
fix: allow root temp base
1 parent ecdac55 commit 7240132

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ fn handleLogin(allocator: std.mem.Allocator, codex_home: []const u8, opts: cli.L
15731573
fn createTempLoginCodexHome(allocator: std.mem.Allocator) ![]u8 {
15741574
const base = try tempBasePathAlloc(allocator);
15751575
defer allocator.free(base);
1576-
try std.fs.cwd().makePath(base);
1576+
try ensureTempBasePath(base);
15771577

15781578
var counter: usize = 0;
15791579
while (counter < 100) : (counter += 1) {
@@ -1597,6 +1597,18 @@ fn createTempLoginCodexHome(allocator: std.mem.Allocator) ![]u8 {
15971597
return error.PathAlreadyExists;
15981598
}
15991599

1600+
fn ensureTempBasePath(base: []const u8) !void {
1601+
std.fs.cwd().makePath(base) catch |err| switch (err) {
1602+
error.BadPathName => try std.fs.cwd().access(base, .{}),
1603+
else => return err,
1604+
};
1605+
}
1606+
1607+
test "temp base path accepts filesystem root" {
1608+
const root = if (builtin.os.tag == .windows) "C:\\" else "/";
1609+
try ensureTempBasePath(root);
1610+
}
1611+
16001612
fn tempBasePathAlloc(allocator: std.mem.Allocator) ![]u8 {
16011613
if (builtin.os.tag == .windows) {
16021614
if (try getNonEmptyEnvVarOwned(allocator, "TEMP")) |path| return path;

0 commit comments

Comments
 (0)