Skip to content

Commit

Permalink
move TempDir to src/os and use the real tmpDir
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jul 9, 2023
1 parent 26e17de commit 9a0d131
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const Command = @This();

const std = @import("std");
const builtin = @import("builtin");
const TempDir = @import("TempDir.zig");
const internal_os = @import("os/main.zig");
const TempDir = internal_os.TempDir;
const mem = std.mem;
const os = std.os;
const debug = std.debug;
Expand Down
1 change: 0 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ pub const GlobalState = struct {
test {
_ = @import("Pty.zig");
_ = @import("Command.zig");
_ = @import("TempDir.zig");
_ = @import("font/main.zig");
_ = @import("renderer.zig");
_ = @import("termio.zig");
Expand Down
8 changes: 6 additions & 2 deletions src/TempDir.zig → src/os/TempDir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
const Dir = std.fs.Dir;
const internal_os = @import("main.zig");

const log = std.log.scoped(.tempdir);

Expand All @@ -28,8 +29,11 @@ pub fn init() !TempDir {
var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined;
var rand_buf: [RANDOM_BYTES]u8 = undefined;

// TODO: use the real temp dir not cwd
const dir = std.fs.cwd();
const dir = dir: {
const cwd = std.fs.cwd();
const tmp_dir = internal_os.tmpDir() orelse break :dir cwd;
break :dir try cwd.openDir(tmp_dir, .{});
};

// We now loop forever until we can find a directory that we can create.
while (true) {
Expand Down
1 change: 1 addition & 0 deletions src/os/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub usingnamespace @import("flatpak.zig");
pub usingnamespace @import("locale.zig");
pub usingnamespace @import("macos_version.zig");
pub usingnamespace @import("mouse.zig");
pub const TempDir = @import("TempDir.zig");

0 comments on commit 9a0d131

Please sign in to comment.