| author | |
| committer | |
| log | b1d1806fef56a72d0df14ad3a54c3074b1e55a69 |
| tree | 8a66e8db31db8edd8f2aeb8f67d5300e8c650214 |
| parent | 0a37ad2ec4daa04a845142508e0dd1326db7ee2d |
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.18 files changed, 41 insertions(+), 41 deletions(-)
lib/compiler/build_runner.zig+1-1| ... | ... | @@ -83,7 +83,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 83 | 83 | .io = io, |
| 84 | 84 | .gpa = gpa, |
| 85 | 85 | .manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}), |
| 86 | .cwd = try process.currentDirAlloc(io, single_threaded_arena.allocator()), | |
| 86 | .cwd = try process.currentPathAlloc(io, single_threaded_arena.allocator()), | |
| 87 | 87 | }, |
| 88 | 88 | .zig_exe = zig_exe, |
| 89 | 89 | .environ_map = try init.environ.createMap(arena), |
lib/std/Build/Cache.zig+4-4| ... | ... | @@ -1315,7 +1315,7 @@ test "cache file and then recall it" { |
| 1315 | 1315 | var tmp = testing.tmpDir(.{}); |
| 1316 | 1316 | defer tmp.cleanup(); |
| 1317 | 1317 | |
| 1318 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1318 | const cwd = try std.process.currentPathAlloc(io, testing.allocator); | |
| 1319 | 1319 | defer testing.allocator.free(cwd); |
| 1320 | 1320 | |
| 1321 | 1321 | const temp_file = "test.txt"; |
| ... | ... | @@ -1383,7 +1383,7 @@ test "check that changing a file makes cache fail" { |
| 1383 | 1383 | var tmp = testing.tmpDir(.{}); |
| 1384 | 1384 | defer tmp.cleanup(); |
| 1385 | 1385 | |
| 1386 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1386 | const cwd = try std.process.currentPathAlloc(io, testing.allocator); | |
| 1387 | 1387 | defer testing.allocator.free(cwd); |
| 1388 | 1388 | |
| 1389 | 1389 | const temp_file = "cache_hash_change_file_test.txt"; |
| ... | ... | @@ -1459,7 +1459,7 @@ test "no file inputs" { |
| 1459 | 1459 | var tmp = testing.tmpDir(.{}); |
| 1460 | 1460 | defer tmp.cleanup(); |
| 1461 | 1461 | |
| 1462 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1462 | const cwd = try std.process.currentPathAlloc(io, testing.allocator); | |
| 1463 | 1463 | defer testing.allocator.free(cwd); |
| 1464 | 1464 | |
| 1465 | 1465 | const temp_manifest_dir = "no_file_inputs_manifest_dir"; |
| ... | ... | @@ -1509,7 +1509,7 @@ test "Manifest with files added after initial hash work" { |
| 1509 | 1509 | var tmp = testing.tmpDir(.{}); |
| 1510 | 1510 | defer tmp.cleanup(); |
| 1511 | 1511 | |
| 1512 | const cwd = try std.process.currentDirAlloc(io, testing.allocator); | |
| 1512 | const cwd = try std.process.currentPathAlloc(io, testing.allocator); | |
| 1513 | 1513 | defer testing.allocator.free(cwd); |
| 1514 | 1514 | |
| 1515 | 1515 | const temp_file1 = "cache_hash_post_file_test1.txt"; |
lib/std/Build/Step/Options.zig+1-1| ... | ... | @@ -519,7 +519,7 @@ test Options { |
| 519 | 519 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 520 | 520 | defer arena.deinit(); |
| 521 | 521 | |
| 522 | const cwd = try std.process.currentDirAlloc(io, std.testing.allocator); | |
| 522 | const cwd = try std.process.currentPathAlloc(io, std.testing.allocator); | |
| 523 | 523 | defer std.testing.allocator.free(cwd); |
| 524 | 524 | |
| 525 | 525 | var graph: std.Build.Graph = .{ |
lib/std/Io.zig+1-1| ... | ... | @@ -665,7 +665,7 @@ pub const VTable = struct { |
| 665 | 665 | lockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!LockedStderr, |
| 666 | 666 | tryLockStderr: *const fn (?*anyopaque, ?Terminal.Mode) Cancelable!?LockedStderr, |
| 667 | 667 | unlockStderr: *const fn (?*anyopaque) void, |
| 668 | processCurrentDir: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentDirError!usize, | |
| 668 | processCurrentPath: *const fn (?*anyopaque, buffer: []u8) std.process.CurrentPathError!usize, | |
| 669 | 669 | processSetCurrentDir: *const fn (?*anyopaque, Dir) std.process.SetCurrentDirError!void, |
| 670 | 670 | processReplace: *const fn (?*anyopaque, std.process.ReplaceOptions) std.process.ReplaceError, |
| 671 | 671 | processReplacePath: *const fn (?*anyopaque, Dir, std.process.ReplaceOptions) std.process.ReplaceError, |
lib/std/Io/Threaded.zig+4-4| ... | ... | @@ -1643,7 +1643,7 @@ pub fn io(t: *Threaded) Io { |
| 1643 | 1643 | .lockStderr = lockStderr, |
| 1644 | 1644 | .tryLockStderr = tryLockStderr, |
| 1645 | 1645 | .unlockStderr = unlockStderr, |
| 1646 | .processCurrentDir = processCurrentDir, | |
| 1646 | .processCurrentPath = processCurrentPath, | |
| 1647 | 1647 | .processSetCurrentDir = processSetCurrentDir, |
| 1648 | 1648 | .processReplace = processReplace, |
| 1649 | 1649 | .processReplacePath = processReplacePath, |
| ... | ... | @@ -1802,7 +1802,7 @@ pub fn ioBasic(t: *Threaded) Io { |
| 1802 | 1802 | .lockStderr = lockStderr, |
| 1803 | 1803 | .tryLockStderr = tryLockStderr, |
| 1804 | 1804 | .unlockStderr = unlockStderr, |
| 1805 | .processCurrentDir = processCurrentDir, | |
| 1805 | .processCurrentPath = processCurrentPath, | |
| 1806 | 1806 | .processSetCurrentDir = processSetCurrentDir, |
| 1807 | 1807 | .processReplace = processReplace, |
| 1808 | 1808 | .processReplacePath = processReplacePath, |
| ... | ... | @@ -12606,7 +12606,7 @@ fn unlockStderr(userdata: ?*anyopaque) void { |
| 12606 | 12606 | process.stderr_thread_mutex.unlock(); |
| 12607 | 12607 | } |
| 12608 | 12608 | |
| 12609 | fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirError!usize { | |
| 12609 | fn processCurrentPath(userdata: ?*anyopaque, buffer: []u8) process.CurrentPathError!usize { | |
| 12610 | 12610 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 12611 | 12611 | _ = t; |
| 12612 | 12612 | if (is_windows) { |
| ... | ... | @@ -12638,7 +12638,7 @@ fn processCurrentDir(userdata: ?*anyopaque, buffer: []u8) process.CurrentDirErro |
| 12638 | 12638 | }; |
| 12639 | 12639 | switch (err) { |
| 12640 | 12640 | .SUCCESS => return std.mem.findScalar(u8, buffer, 0).?, |
| 12641 | .NOENT => return error.CurrentWorkingDirectoryUnlinked, | |
| 12641 | .NOENT => return error.CurrentDirUnlinked, | |
| 12642 | 12642 | .RANGE => return error.NameTooLong, |
| 12643 | 12643 | .FAULT => |e| return errnoBug(e), |
| 12644 | 12644 | .INVAL => |e| return errnoBug(e), |
lib/std/fs/test.zig+1-1| ... | ... | @@ -1787,7 +1787,7 @@ test "open file with exclusive nonblocking lock twice (absolute paths)" { |
| 1787 | 1787 | |
| 1788 | 1788 | const gpa = testing.allocator; |
| 1789 | 1789 | |
| 1790 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 1790 | const cwd = try std.process.currentPathAlloc(io, gpa); | |
| 1791 | 1791 | defer gpa.free(cwd); |
| 1792 | 1792 | |
| 1793 | 1793 | const filename = try Dir.path.resolve(gpa, &.{ cwd, sub_path }); |
lib/std/process.zig+11-11| ... | ... | @@ -63,22 +63,22 @@ pub const Init = struct { |
| 63 | 63 | }; |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | pub const CurrentDirError = error{ | |
| 66 | pub const CurrentPathError = error{ | |
| 67 | 67 | NameTooLong, |
| 68 | 68 | /// Not possible on Windows. Always returned on WASI. |
| 69 | CurrentWorkingDirectoryUnlinked, | |
| 69 | CurrentDirUnlinked, | |
| 70 | 70 | } || Io.UnexpectedError; |
| 71 | 71 | |
| 72 | 72 | /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). |
| 73 | 73 | /// On other platforms, the result is an opaque sequence of bytes with no |
| 74 | 74 | /// particular encoding. |
| 75 | pub fn currentDir(io: Io, buffer: []u8) CurrentDirError!usize { | |
| 76 | return io.vtable.processCurrentDir(io.userdata, buffer); | |
| 75 | pub fn currentPath(io: Io, buffer: []u8) CurrentPathError!usize { | |
| 76 | return io.vtable.processCurrentPath(io.userdata, buffer); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | pub const CurrentDirAllocError = Allocator.Error || error{ | |
| 79 | pub const CurrentPathAllocError = Allocator.Error || error{ | |
| 80 | 80 | /// Not possible on Windows. Always returned on WASI. |
| 81 | CurrentWorkingDirectoryUnlinked, | |
| 81 | CurrentDirUnlinked, | |
| 82 | 82 | } || Io.UnexpectedError; |
| 83 | 83 | |
| 84 | 84 | /// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/). |
| ... | ... | @@ -86,17 +86,17 @@ pub const CurrentDirAllocError = Allocator.Error || error{ |
| 86 | 86 | /// particular encoding. |
| 87 | 87 | /// |
| 88 | 88 | /// Caller owns returned memory. |
| 89 | pub fn currentDirAlloc(io: Io, allocator: Allocator) CurrentDirAllocError![:0]u8 { | |
| 89 | pub fn currentPathAlloc(io: Io, allocator: Allocator) CurrentPathAllocError![:0]u8 { | |
| 90 | 90 | var buffer: [max_path_bytes]u8 = undefined; |
| 91 | const n = currentDir(io, &buffer) catch |err| switch (err) { | |
| 91 | const n = currentPath(io, &buffer) catch |err| switch (err) { | |
| 92 | 92 | error.NameTooLong => unreachable, |
| 93 | 93 | else => |e| return e, |
| 94 | 94 | }; |
| 95 | 95 | return allocator.dupeZ(u8, buffer[0..n]); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | test currentDirAlloc { | |
| 99 | const cwd = try currentDirAlloc(testing.io, testing.allocator); | |
| 98 | test currentPathAlloc { | |
| 99 | const cwd = try currentPathAlloc(testing.io, testing.allocator); | |
| 100 | 100 | testing.allocator.free(cwd); |
| 101 | 101 | } |
| 102 | 102 | |
| ... | ... | @@ -453,7 +453,7 @@ pub fn spawnPath(io: Io, dir: Io.Dir, options: SpawnOptions) SpawnError!Child { |
| 453 | 453 | return io.vtable.processSpawnPath(io.userdata, dir, options); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | pub const RunError = CurrentDirError || posix.ReadError || SpawnError || posix.PollError || error{ | |
| 456 | pub const RunError = CurrentPathError || posix.ReadError || SpawnError || posix.PollError || error{ | |
| 457 | 457 | StdoutStreamTooLong, |
| 458 | 458 | StderrStreamTooLong, |
| 459 | 459 | }; |
src/introspect.zig+4-4| ... | ... | @@ -51,23 +51,23 @@ pub fn findZigLibDir(gpa: Allocator, io: Io) !Cache.Directory { |
| 51 | 51 | return findZigLibDirFromSelfExe(gpa, io, cwd_path, self_exe_path); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | /// Like `std.process.currentDirAlloc`, but also resolves the path with `Dir.path.resolve`. This | |
| 54 | /// Like `std.process.currentPathAlloc`, but also resolves the path with `Dir.path.resolve`. This | |
| 55 | 55 | /// means the path has no repeated separators, no "." or ".." components, and no trailing separator. |
| 56 | 56 | /// On WASI, "" is returned instead of ".". |
| 57 | 57 | pub fn getResolvedCwd(io: Io, gpa: Allocator) error{ |
| 58 | 58 | OutOfMemory, |
| 59 | CurrentWorkingDirectoryUnlinked, | |
| 59 | CurrentDirUnlinked, | |
| 60 | 60 | Unexpected, |
| 61 | 61 | }![]u8 { |
| 62 | 62 | if (builtin.target.os.tag == .wasi) { |
| 63 | 63 | if (std.debug.runtime_safety) { |
| 64 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 64 | const cwd = try std.process.currentPathAlloc(io, gpa); | |
| 65 | 65 | defer gpa.free(cwd); |
| 66 | 66 | assert(mem.eql(u8, cwd, ".")); |
| 67 | 67 | } |
| 68 | 68 | return ""; |
| 69 | 69 | } |
| 70 | const cwd = try std.process.currentDirAlloc(io, gpa); | |
| 70 | const cwd = try std.process.currentPathAlloc(io, gpa); | |
| 71 | 71 | defer gpa.free(cwd); |
| 72 | 72 | const resolved = try Dir.path.resolve(gpa, &.{cwd}); |
| 73 | 73 | assert(Dir.path.isAbsolute(resolved)); |
test/standalone/child_process/main.zig+1-1| ... | ... | @@ -16,7 +16,7 @@ pub fn main(init: std.process.Init.Minimal) !void { |
| 16 | 16 | defer threaded.deinit(); |
| 17 | 17 | const io = threaded.io(); |
| 18 | 18 | |
| 19 | const process_cwd_path = try std.process.currentDirAlloc(io, gpa); | |
| 19 | const process_cwd_path = try std.process.currentPathAlloc(io, gpa); | |
| 20 | 20 | defer gpa.free(process_cwd_path); |
| 21 | 21 | |
| 22 | 22 | var environ_map = try init.environ.createMap(gpa); |
test/standalone/posix/cwd.zig+5-5| ... | ... | @@ -28,13 +28,13 @@ pub fn main(init: std.process.Init) !void { |
| 28 | 28 | // get current working directory and expect it to match given path |
| 29 | 29 | fn expect_cwd(io: Io, expected_cwd: []const u8) !void { |
| 30 | 30 | var cwd_buf: [path_max]u8 = undefined; |
| 31 | const actual_cwd = cwd_buf[0..try std.process.currentDir(io, &cwd_buf)]; | |
| 31 | const actual_cwd = cwd_buf[0..try std.process.currentPath(io, &cwd_buf)]; | |
| 32 | 32 | try std.testing.expectEqualStrings(actual_cwd, expected_cwd); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | fn test_chdir_self(io: Io) !void { |
| 36 | 36 | var old_cwd_buf: [path_max]u8 = undefined; |
| 37 | const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)]; | |
| 37 | const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)]; | |
| 38 | 38 | |
| 39 | 39 | // Try changing to the current directory |
| 40 | 40 | try std.Io.Threaded.chdir(old_cwd); |
| ... | ... | @@ -43,7 +43,7 @@ fn test_chdir_self(io: Io) !void { |
| 43 | 43 | |
| 44 | 44 | fn test_chdir_absolute(io: Io) !void { |
| 45 | 45 | var old_cwd_buf: [path_max]u8 = undefined; |
| 46 | const old_cwd = old_cwd_buf[0..try std.process.currentDir(io, &old_cwd_buf)]; | |
| 46 | const old_cwd = old_cwd_buf[0..try std.process.currentPath(io, &old_cwd_buf)]; | |
| 47 | 47 | |
| 48 | 48 | const parent = std.fs.path.dirname(old_cwd) orelse unreachable; // old_cwd should be absolute |
| 49 | 49 | |
| ... | ... | @@ -62,7 +62,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void { |
| 62 | 62 | |
| 63 | 63 | // Capture base working directory path, to build expected full path |
| 64 | 64 | var base_cwd_buf: [path_max]u8 = undefined; |
| 65 | const base_cwd = base_cwd_buf[0..try std.process.currentDir(io, &base_cwd_buf)]; | |
| 65 | const base_cwd = base_cwd_buf[0..try std.process.currentPath(io, &base_cwd_buf)]; | |
| 66 | 66 | |
| 67 | 67 | const expected_path = try std.fs.path.resolve(gpa, &.{ base_cwd, subdir_path }); |
| 68 | 68 | defer gpa.free(expected_path); |
| ... | ... | @@ -71,7 +71,7 @@ fn test_chdir_relative(gpa: Allocator, io: Io, tmp_dir: Io.Dir) !void { |
| 71 | 71 | try std.Io.Threaded.chdir(subdir_path); |
| 72 | 72 | |
| 73 | 73 | var new_cwd_buf: [path_max]u8 = undefined; |
| 74 | const new_cwd = new_cwd_buf[0..try std.process.currentDir(io, &new_cwd_buf)]; | |
| 74 | const new_cwd = new_cwd_buf[0..try std.process.currentPath(io, &new_cwd_buf)]; | |
| 75 | 75 | |
| 76 | 76 | // On Windows, fs.path.resolve returns an uppercase drive letter, but the drive letter returned by getcwd may be lowercase |
| 77 | 77 | const resolved_cwd = try std.fs.path.resolve(gpa, &.{new_cwd}); |
test/standalone/self_exe_symlink/create-symlink.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ pub fn main(init: std.process.Init) !void { |
| 9 | 9 | const exe_path = it.next() orelse unreachable; |
| 10 | 10 | const symlink_path = it.next() orelse unreachable; |
| 11 | 11 | |
| 12 | const cwd = try std.process.currentDirAlloc(io, init.arena.allocator()); | |
| 12 | const cwd = try std.process.currentPathAlloc(io, init.arena.allocator()); | |
| 13 | 13 | |
| 14 | 14 | // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`. |
| 15 | 15 | const exe_rel_path = try std.fs.path.relative(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path); |
test/standalone/windows_paths/relative.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ pub fn main(init: std.process.Init) !void { |
| 4 | 4 | const arena = init.arena.allocator(); |
| 5 | 5 | const args = try init.minimal.args.toSlice(arena); |
| 6 | 6 | const io = init.io; |
| 7 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 7 | const cwd_path = try std.process.currentPathAlloc(io, arena); | |
| 8 | 8 | |
| 9 | 9 | if (args.len < 3) return error.MissingArgs; |
| 10 | 10 |
test/standalone/windows_paths/test.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ pub fn main(init: std.process.Init) !void { |
| 10 | 10 | |
| 11 | 11 | const exe_path = args[1]; |
| 12 | 12 | |
| 13 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 13 | const cwd_path = try std.process.currentPathAlloc(io, arena); | |
| 14 | 14 | const parsed_cwd_path = std.fs.path.parsePathWindows(u8, cwd_path); |
| 15 | 15 | |
| 16 | 16 | if (parsed_cwd_path.kind == .drive_absolute and !std.ascii.isAlphabetic(cwd_path[0])) { |
test/standalone/windows_spawn/main.zig+1-1| ... | ... | @@ -8,7 +8,7 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral; |
| 8 | 8 | pub fn main(init: std.process.Init) !void { |
| 9 | 9 | const gpa = init.gpa; |
| 10 | 10 | const io = init.io; |
| 11 | const process_cwd_path = try std.process.currentDirAlloc(io, init.arena.allocator()); | |
| 11 | const process_cwd_path = try std.process.currentPathAlloc(io, init.arena.allocator()); | |
| 12 | 12 | var initial_process_cwd = try Io.Dir.cwd().openDir(io, ".", .{}); |
| 13 | 13 | defer initial_process_cwd.close(io); |
| 14 | 14 |
tools/doctest.zig+1-1| ... | ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { |
| 33 | 33 | const arena = init.arena.allocator(); |
| 34 | 34 | const io = init.io; |
| 35 | 35 | const environ_map = init.environ_map; |
| 36 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 36 | const cwd_path = try std.process.currentPathAlloc(io, arena); | |
| 37 | 37 | |
| 38 | 38 | try environ_map.put("CLICOLOR_FORCE", "1"); |
| 39 | 39 |
tools/incr-check.zig+1-1| ... | ... | @@ -32,7 +32,7 @@ pub fn main(init: std.process.Init) !void { |
| 32 | 32 | const arena = init.arena.allocator(); |
| 33 | 33 | const io = init.io; |
| 34 | 34 | const environ_map = init.environ_map; |
| 35 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 35 | const cwd_path = try std.process.currentPathAlloc(io, arena); | |
| 36 | 36 | |
| 37 | 37 | var opt_zig_exe: ?[]const u8 = null; |
| 38 | 38 | var opt_input_file_name: ?[]const u8 = null; |
tools/process_headers.zig+1-1| ... | ... | @@ -145,7 +145,7 @@ pub fn main(init: std.process.Init) !void { |
| 145 | 145 | const arena = init.arena.allocator(); |
| 146 | 146 | const io = init.io; |
| 147 | 147 | const args = try init.minimal.args.toSlice(arena); |
| 148 | const cwd_path = try std.process.currentDirAlloc(io, arena); | |
| 148 | const cwd_path = try std.process.currentPathAlloc(io, arena); | |
| 149 | 149 | const environ_map = init.environ_map; |
| 150 | 150 | |
| 151 | 151 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
tools/update-linux-headers.zig+1-1| ... | ... | @@ -146,7 +146,7 @@ pub fn main(init: std.process.Init) !void { |
| 146 | 146 | const io = init.io; |
| 147 | 147 | const args = try init.minimal.args.toSlice(arena); |
| 148 | 148 | const environ_map = init.environ_map; |
| 149 | const cwd = try std.process.currentDirAlloc(io, arena); | |
| 149 | const cwd = try std.process.currentPathAlloc(io, arena); | |
| 150 | 150 | |
| 151 | 151 | var search_paths = std.array_list.Managed([]const u8).init(arena); |
| 152 | 152 | var opt_out_dir: ?[]const u8 = null; |