Merge branch 'LemonBoy-travbug'

closes #4747
This commit is contained in:
Andrew Kelley 2020-03-18 16:42:58 -04:00
commit 7a361751e5
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
20 changed files with 158 additions and 139 deletions

View File

@ -48,7 +48,7 @@ pub fn main() !void {
var toc = try genToc(allocator, &tokenizer);
try fs.cwd().makePath(tmp_dir_name);
defer fs.deleteTree(tmp_dir_name) catch {};
defer fs.cwd().deleteTree(tmp_dir_name) catch {};
try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe);
try buffered_out_stream.flush();

View File

@ -377,7 +377,7 @@ pub const Builder = struct {
if (self.verbose) {
warn("rm {}\n", .{full_path});
}
fs.deleteTree(full_path) catch {};
fs.cwd().deleteTree(full_path) catch {};
}
// TODO remove empty directories
@ -2156,10 +2156,10 @@ pub const LibExeObjStep = struct {
const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
if (self.output_dir) |output_dir| {
var src_dir = try std.fs.cwd().openDirTraverse(build_output_dir);
var src_dir = try std.fs.cwd().openDir(build_output_dir, .{ .iterate = true });
defer src_dir.close();
var dest_dir = try std.fs.cwd().openDirList(output_dir);
var dest_dir = try std.fs.cwd().openDir(output_dir, .{});
defer dest_dir.close();
var it = src_dir.iterate();
@ -2365,7 +2365,7 @@ pub const RemoveDirStep = struct {
const self = @fieldParentPtr(RemoveDirStep, "step", step);
const full_path = self.builder.pathFromRoot(self.dir_path);
fs.deleteTree(full_path) catch |err| {
fs.cwd().deleteTree(full_path) catch |err| {
warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
return err;
};

View File

@ -78,7 +78,7 @@ pub const WriteFileStep = struct {
warn("unable to make path {}: {}\n", .{ self.output_dir, @errorName(err) });
return err;
};
var dir = try fs.cwd().openDirTraverse(self.output_dir);
var dir = try fs.cwd().openDir(self.output_dir, .{});
defer dir.close();
for (self.files.toSliceConst()) |file| {
dir.writeFile(file.basename, file.bytes) catch |err| {

View File

@ -261,28 +261,6 @@ pub fn deleteDirW(dir_path: [*:0]const u16) !void {
return os.rmdirW(dir_path);
}
/// Removes a symlink, file, or directory.
/// If `full_path` is relative, this is equivalent to `Dir.deleteTree` with the
/// current working directory as the open directory handle.
/// If `full_path` is absolute, this is equivalent to `Dir.deleteTree` with the
/// base directory.
pub fn deleteTree(full_path: []const u8) !void {
if (path.isAbsolute(full_path)) {
const dirname = path.dirname(full_path) orelse return error{
/// Attempt to remove the root file system path.
/// This error is unreachable if `full_path` is relative.
CannotDeleteRootDirectory,
}.CannotDeleteRootDirectory;
var dir = try cwd().openDirList(dirname);
defer dir.close();
return dir.deleteTree(path.basename(full_path));
} else {
return cwd().deleteTree(full_path);
}
}
pub const Dir = struct {
fd: os.fd_t,
@ -339,7 +317,7 @@ pub const Dir = struct {
if (rc == 0) return null;
if (rc < 0) {
switch (os.errno(rc)) {
os.EBADF => unreachable,
os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
os.EFAULT => unreachable,
os.ENOTDIR => unreachable,
os.EINVAL => unreachable,
@ -388,7 +366,7 @@ pub const Dir = struct {
);
switch (os.errno(rc)) {
0 => {},
os.EBADF => unreachable,
os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
os.EFAULT => unreachable,
os.ENOTDIR => unreachable,
os.EINVAL => unreachable,
@ -444,7 +422,7 @@ pub const Dir = struct {
const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
switch (os.linux.getErrno(rc)) {
0 => {},
os.EBADF => unreachable,
os.EBADF => unreachable, // Dir is invalid or was opened without iteration ability
os.EFAULT => unreachable,
os.ENOTDIR => unreachable,
os.EINVAL => unreachable,
@ -518,7 +496,8 @@ pub const Dir = struct {
self.end_index = io.Information;
switch (rc) {
.SUCCESS => {},
.ACCESS_DENIED => return error.AccessDenied,
.ACCESS_DENIED => return error.AccessDenied, // Double-check that the Dir was opened with iteration ability
else => return w.unexpectedStatus(rc),
}
}
@ -596,16 +575,6 @@ pub const Dir = struct {
DeviceBusy,
} || os.UnexpectedError;
/// Deprecated; call `cwd().openDirList` directly.
pub fn open(dir_path: []const u8) OpenError!Dir {
return cwd().openDirList(dir_path);
}
/// Deprecated; call `cwd().openDirListC` directly.
pub fn openC(dir_path_c: [*:0]const u8) OpenError!Dir {
return cwd().openDirListC(dir_path_c);
}
pub fn close(self: *Dir) void {
if (need_async_thread) {
std.event.Loop.instance.?.close(self.fd);
@ -792,79 +761,61 @@ pub const Dir = struct {
try os.fchdir(self.fd);
}
/// Deprecated; call `openDirList` directly.
pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir {
return self.openDirList(sub_path);
}
pub const OpenDirOptions = struct {
/// `true` means the opened directory can be used as the `Dir` parameter
/// for functions which operate based on an open directory handle. When `false`,
/// such operations are Illegal Behavior.
access_sub_paths: bool = true,
/// Deprecated; call `openDirListC` directly.
pub fn openDirC(self: Dir, sub_path_c: [*:0]const u8) OpenError!Dir {
return self.openDirListC(sub_path_c);
}
/// `true` means the opened directory can be scanned for the files and sub-directories
/// of the result. It means the `iterate` function can be called.
iterate: bool = false,
};
/// Opens a directory at the given path with the ability to access subpaths
/// of the result. Calling `iterate` on the result is illegal behavior; to
/// list the contents of a directory, open it with `openDirList`.
///
/// Call `close` on the result when done.
/// Opens a directory at the given path. The directory is a system resource that remains
/// open until `close` is called on the result.
///
/// Asserts that the path parameter has no null bytes.
/// TODO collapse this and `openDirList` into one function with an options parameter
pub fn openDirTraverse(self: Dir, sub_path: []const u8) OpenError!Dir {
pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
if (builtin.os.tag == .windows) {
const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
return self.openDirTraverseW(&sub_path_w);
return self.openDirW(&sub_path_w, args);
} else {
const sub_path_c = try os.toPosixPath(sub_path);
return self.openDirC(&sub_path_c, args);
}
const sub_path_c = try os.toPosixPath(sub_path);
return self.openDirTraverseC(&sub_path_c);
}
/// Opens a directory at the given path with the ability to access subpaths and list contents
/// of the result. If the ability to list contents is unneeded, `openDirTraverse` acts the
/// same and may be more efficient.
///
/// Call `close` on the result when done.
///
/// Asserts that the path parameter has no null bytes.
/// TODO collapse this and `openDirTraverse` into one function with an options parameter
pub fn openDirList(self: Dir, sub_path: []const u8) OpenError!Dir {
if (builtin.os.tag == .windows) {
const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
return self.openDirListW(&sub_path_w);
}
const sub_path_c = try os.toPosixPath(sub_path);
return self.openDirListC(&sub_path_c);
}
/// Same as `openDirTraverse` except the parameter is null-terminated.
pub fn openDirTraverseC(self: Dir, sub_path_c: [*:0]const u8) OpenError!Dir {
/// Same as `openDir` except the parameter is null-terminated.
pub fn openDirC(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
if (builtin.os.tag == .windows) {
const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
return self.openDirTraverseW(&sub_path_w);
} else {
return self.openDirW(&sub_path_w, args);
} else if (!args.iterate) {
const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;
return self.openDirFlagsC(sub_path_c, os.O_RDONLY | os.O_CLOEXEC | O_PATH);
}
}
/// Same as `openDirList` except the parameter is null-terminated.
pub fn openDirListC(self: Dir, sub_path_c: [*:0]const u8) OpenError!Dir {
if (builtin.os.tag == .windows) {
const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
return self.openDirListW(&sub_path_w);
return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH);
} else {
return self.openDirFlagsC(sub_path_c, os.O_RDONLY | os.O_CLOEXEC);
return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC);
}
}
/// Same as `openDir` except the path parameter is WTF-16 encoded, NT-prefixed.
/// This function asserts the target OS is Windows.
pub fn openDirW(self: Dir, sub_path_w: [*:0]const u16, args: OpenDirOptions) OpenError!Dir {
const w = os.windows;
// TODO remove some of these flags if args.access_sub_paths is false
const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
w.SYNCHRONIZE | w.FILE_TRAVERSE;
const flags: u32 = if (args.iterate) base_flags | w.FILE_LIST_DIRECTORY else base_flags;
return self.openDirAccessMaskW(sub_path_w, flags);
}
/// `flags` must contain `os.O_DIRECTORY`.
fn openDirFlagsC(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
const os_flags = flags | os.O_DIRECTORY;
const result = if (need_async_thread)
std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, 0)
std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0)
else
os.openatC(self.fd, sub_path_c, os_flags, 0);
os.openatC(self.fd, sub_path_c, flags, 0);
const fd = result catch |err| switch (err) {
error.FileTooBig => unreachable, // can't happen for directories
error.IsDir => unreachable, // we're providing O_DIRECTORY
@ -875,22 +826,6 @@ pub const Dir = struct {
return Dir{ .fd = fd };
}
/// Same as `openDirTraverse` except the path parameter is UTF16LE, NT-prefixed.
/// This function is Windows-only.
pub fn openDirTraverseW(self: Dir, sub_path_w: [*:0]const u16) OpenError!Dir {
const w = os.windows;
return self.openDirAccessMaskW(sub_path_w, w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE);
}
/// Same as `openDirList` except the path parameter is UTF16LE, NT-prefixed.
/// This function is Windows-only.
pub fn openDirListW(self: Dir, sub_path_w: [*:0]const u16) OpenError!Dir {
const w = os.windows;
return self.openDirAccessMaskW(sub_path_w, w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA | w.SYNCHRONIZE | w.FILE_TRAVERSE | w.FILE_LIST_DIRECTORY);
}
fn openDirAccessMaskW(self: Dir, sub_path_w: [*:0]const u16, access_mask: u32) OpenError!Dir {
const w = os.windows;
@ -1111,7 +1046,7 @@ pub const Dir = struct {
error.Unexpected,
=> |e| return e,
}
var dir = self.openDirList(sub_path) catch |err| switch (err) {
var dir = self.openDir(sub_path, .{ .iterate = true }) catch |err| switch (err) {
error.NotDir => {
if (got_access_denied) {
return error.AccessDenied;
@ -1144,7 +1079,6 @@ pub const Dir = struct {
var dir_name_buf: [MAX_PATH_BYTES]u8 = undefined;
var dir_name: []const u8 = sub_path;
var parent_dir = self;
// Here we must avoid recursion, in order to provide O(1) memory guarantee of this function.
// Go through each entry and if it is not a directory, delete it. If it is a directory,
@ -1176,7 +1110,7 @@ pub const Dir = struct {
=> |e| return e,
}
const new_dir = dir.openDirList(entry.name) catch |err| switch (err) {
const new_dir = dir.openDir(entry.name, .{ .iterate = true }) catch |err| switch (err) {
error.NotDir => {
if (got_access_denied) {
return error.AccessDenied;
@ -1349,7 +1283,7 @@ pub const Dir = struct {
}
};
/// Returns an handle to the current working directory that is open for traversal.
/// Returns an handle to the current working directory. It is not opened with iteration capability.
/// Closing the returned `Dir` is checked illegal behavior. Iterating over the result is illegal behavior.
/// On POSIX targets, this function is comptime-callable.
pub fn cwd() Dir {
@ -1427,6 +1361,25 @@ pub fn deleteFileAbsoluteW(absolute_path_w: [*:0]const u16) DeleteFileError!void
return cwd().deleteFileW(absolute_path_w);
}
/// Removes a symlink, file, or directory.
/// This is equivalent to `Dir.deleteTree` with the base directory.
/// Asserts that the path is absolute. See `Dir.deleteTree` for a function that
/// operates on both absolute and relative paths.
/// Asserts that the path parameter has no null bytes.
pub fn deleteTreeAbsolute(absolute_path: []const u8) !void {
assert(path.isAbsolute(absolute_path));
const dirname = path.dirname(absolute_path) orelse return error{
/// Attempt to remove the root file system path.
/// This error is unreachable if `absolute_path` is relative.
CannotDeleteRootDirectory,
}.CannotDeleteRootDirectory;
var dir = try cwd().openDir(dirname, .{});
defer dir.close();
return dir.deleteTree(path.basename(absolute_path));
}
pub const Walker = struct {
stack: std.ArrayList(StackItem),
name_buffer: std.Buffer,
@ -1461,7 +1414,7 @@ pub const Walker = struct {
try self.name_buffer.appendByte(path.sep);
try self.name_buffer.append(base.name);
if (base.kind == .Directory) {
var new_dir = top.dir_it.dir.openDirList(base.name) catch |err| switch (err) {
var new_dir = top.dir_it.dir.openDir(base.name, .{ .iterate = true }) catch |err| switch (err) {
error.NameTooLong => unreachable, // no path sep in base.name
else => |e| return e,
};
@ -1499,7 +1452,7 @@ pub const Walker = struct {
pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
assert(!mem.endsWith(u8, dir_path, path.sep_str));
var dir = try cwd().openDirList(dir_path);
var dir = try cwd().openDir(dir_path, .{ .iterate = true });
errdefer dir.close();
var name_buffer = try std.Buffer.init(allocator, dir_path);

View File

@ -619,7 +619,7 @@ test "write a file, watch it, write it again" {
if (true) return error.SkipZigTest;
try fs.cwd().makePath(test_tmp_dir);
defer os.deleteTree(test_tmp_dir) catch {};
defer fs.cwd().deleteTree(test_tmp_dir) catch {};
const allocator = std.heap.page_allocator;
return testFsWatch(&allocator);

View File

@ -3163,6 +3163,31 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
}
}
pub const FcntlError = error{
PermissionDenied,
FileBusy,
ProcessFdQuotaExceeded,
Locked,
} || UnexpectedError;
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
while (true) {
const rc = system.fcntl(fd, cmd, arg);
switch (errno(rc)) {
0 => return @intCast(usize, rc),
EINTR => continue,
EACCES => return error.Locked,
EBADF => unreachable,
EBUSY => return error.FileBusy,
EINVAL => unreachable, // invalid parameters
EPERM => return error.PermissionDenied,
EMFILE => return error.ProcessFdQuotaExceeded,
ENOTDIR => unreachable, // invalid parameter
else => |err| return unexpectedErrno(err),
}
}
}
pub const RealPathError = error{
FileNotFound,
AccessDenied,

View File

@ -283,6 +283,8 @@ pub const F_LOCK = 1;
pub const F_TLOCK = 2;
pub const F_TEST = 3;
pub const FD_CLOEXEC = 1;
pub const AT_FDCWD = -328243;
pub const AT_SYMLINK_NOFOLLOW = 1;
pub const AT_REMOVEDIR = 2;

View File

@ -355,6 +355,8 @@ pub const F_GETOWN_EX = 16;
pub const F_GETOWNER_UIDS = 17;
pub const FD_CLOEXEC = 1;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;

View File

@ -136,6 +136,8 @@ pub const MAP_FIXED_NOREPLACE = 0x100000;
/// For anonymous mmap, memory could be uninitialized
pub const MAP_UNINITIALIZED = 0x4000000;
pub const FD_CLOEXEC = 1;
pub const F_OK = 0;
pub const X_OK = 1;
pub const W_OK = 2;

View File

@ -312,6 +312,8 @@ pub const F_GETLK = 7;
pub const F_SETLK = 8;
pub const F_SETLKW = 9;
pub const FD_CLOEXEC = 1;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;

View File

@ -588,6 +588,10 @@ pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize {
return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
}
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
return syscall3(SYS_fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg);
}
var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
// We must follow the C calling convention when we call into the VDSO

View File

@ -1,7 +1,8 @@
const std = @import("../std.zig");
const os = std.os;
const testing = std.testing;
const expect = std.testing.expect;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
const io = std.io;
const fs = std.fs;
const mem = std.mem;
@ -19,8 +20,8 @@ test "makePath, put some files in it, deleteTree" {
try fs.cwd().makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
try fs.deleteTree("os_test_tmp");
if (fs.cwd().openDirTraverse("os_test_tmp")) |dir| {
try fs.cwd().deleteTree("os_test_tmp");
if (fs.cwd().openDir("os_test_tmp", .{})) |dir| {
@panic("expected error");
} else |err| {
expect(err == error.FileNotFound);
@ -37,7 +38,7 @@ test "access file" {
try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
try os.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", os.F_OK);
try fs.deleteTree("os_test_tmp");
try fs.cwd().deleteTree("os_test_tmp");
}
fn testThreadIdFn(thread_id: *Thread.Id) void {
@ -46,9 +47,9 @@ fn testThreadIdFn(thread_id: *Thread.Id) void {
test "sendfile" {
try fs.cwd().makePath("os_test_tmp");
defer fs.deleteTree("os_test_tmp") catch {};
defer fs.cwd().deleteTree("os_test_tmp") catch {};
var dir = try fs.cwd().openDirList("os_test_tmp");
var dir = try fs.cwd().openDir("os_test_tmp", .{});
defer dir.close();
const line1 = "line1\n";
@ -446,3 +447,32 @@ test "getenv" {
expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null);
}
}
test "fcntl" {
if (builtin.os.tag == .windows)
return error.SkipZigTest;
const test_out_file = "os_tmp_test";
const file = try fs.cwd().createFile(test_out_file, .{});
defer {
file.close();
fs.cwd().deleteFile(test_out_file) catch {};
}
// Note: The test assumes createFile opens the file with O_CLOEXEC
{
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
expect((flags & os.FD_CLOEXEC) != 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, 0);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
expect((flags & os.FD_CLOEXEC) == 0);
}
{
_ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC);
const flags = try os.fcntl(file.handle, os.F_GETFD, 0);
expect((flags & os.FD_CLOEXEC) != 0);
}
}

View File

@ -754,7 +754,7 @@ pub const NativeTargetInfo = struct {
const rpath_list = mem.toSliceConst(u8, @ptrCast([*:0]u8, strtab[rpoff..].ptr));
var it = mem.tokenize(rpath_list, ":");
while (it.next()) |rpath| {
var dir = fs.cwd().openDirList(rpath) catch |err| switch (err) {
var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
error.NameTooLong => unreachable,
error.InvalidUtf8 => unreachable,
error.BadPathName => unreachable,

View File

@ -520,8 +520,7 @@ pub const Compilation = struct {
if (comp.tmp_dir.getOrNull()) |tmp_dir_result|
if (tmp_dir_result.*) |tmp_dir| {
// TODO evented I/O?
fs.deleteTree(tmp_dir) catch {};
fs.cwd().deleteTree(tmp_dir) catch {};
} else |_| {};
}

View File

@ -280,7 +280,7 @@ pub const LibCInstallation = struct {
// search in reverse order
const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
var search_dir = fs.cwd().openDirList(search_path) catch |err| switch (err) {
var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@ -335,7 +335,7 @@ pub const LibCInstallation = struct {
const stream = result_buf.outStream();
try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) {
var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@ -382,7 +382,7 @@ pub const LibCInstallation = struct {
const stream = result_buf.outStream();
try stream.print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir });
var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) {
var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@ -437,7 +437,7 @@ pub const LibCInstallation = struct {
const stream = result_buf.outStream();
try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir });
var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) {
var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,
@ -475,7 +475,7 @@ pub const LibCInstallation = struct {
try result_buf.append("\\include");
var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) {
var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
error.FileNotFound,
error.NotDir,
error.NoDevice,

View File

@ -734,7 +734,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
max_src_size,
) catch |err| switch (err) {
error.IsDir, error.AccessDenied => {
var dir = try fs.cwd().openDirList(file_path);
var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
defer dir.close();
var group = event.Group(FmtError!void).init(fmt.allocator);

View File

@ -72,7 +72,7 @@ pub fn cmdTargets(
};
defer allocator.free(zig_lib_dir);
var dir = try std.fs.cwd().openDirList(zig_lib_dir);
var dir = try std.fs.cwd().openDir(zig_lib_dir, .{});
defer dir.close();
const vers_txt = try dir.readFileAlloc(allocator, "libc/glibc/vers.txt", 10 * 1024);

View File

@ -319,7 +319,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
error.IsDir, error.AccessDenied => {
// TODO make event based (and dir.next())
var dir = try fs.cwd().openDirList(file_path);
var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
defer dir.close();
var dir_it = dir.iterate();

View File

@ -57,11 +57,11 @@ pub const TestContext = struct {
errdefer allocator.free(self.zig_lib_dir);
try std.fs.cwd().makePath(tmp_dir_name);
errdefer std.fs.deleteTree(tmp_dir_name) catch {};
errdefer std.fs.cwd().deleteTree(tmp_dir_name) catch {};
}
fn deinit(self: *TestContext) void {
std.fs.deleteTree(tmp_dir_name) catch {};
std.fs.cwd().deleteTree(tmp_dir_name) catch {};
allocator.free(self.zig_lib_dir);
self.zig_compiler.deinit();
}

View File

@ -36,7 +36,7 @@ pub fn main() !void {
testMissingOutputPath,
};
for (test_fns) |testFn| {
try fs.deleteTree(dir_path);
try fs.cwd().deleteTree(dir_path);
try fs.cwd().makeDir(dir_path);
try testFn(zig_exe, dir_path);
}