Commit 4014a8e4b4

Jonathan S <gereeter+code@gmail.com>
2019-11-22 23:32:50
Avoid deprecated cwd-based functions for opening directories, preferring to open explicitly relative to `Dir.cwd()`.
1 parent 0013342
Changed files (5)
lib/std/os/test.zig
@@ -20,7 +20,7 @@ test "makePath, put some files in it, deleteTree" {
     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.Dir.open("os_test_tmp")) |dir| {
+    if (fs.Dir.cwd().openDirTraverse("os_test_tmp")) |dir| {
         @panic("expected error");
     } else |err| {
         expect(err == error.FileNotFound);
lib/std/fs.zig
@@ -350,7 +350,7 @@ pub fn deleteTree(full_path: []const u8) !void {
             CannotDeleteRootDirectory,
         }.CannotDeleteRootDirectory;
 
-        var dir = try Dir.open(dirname);
+        var dir = try Dir.cwd().openDirList(dirname);
         defer dir.close();
 
         return dir.deleteTree(path.basename(full_path));
@@ -1066,7 +1066,7 @@ pub const Dir = struct {
                 error.Unexpected,
                 => |e| return e,
             }
-            var dir = self.openDir(sub_path) catch |err| switch (err) {
+            var dir = self.openDirList(sub_path) catch |err| switch (err) {
                 error.NotDir => {
                     if (got_access_denied) {
                         return error.AccessDenied;
@@ -1131,7 +1131,7 @@ pub const Dir = struct {
                         => |e| return e,
                     }
 
-                    const new_dir = dir.openDir(entry.name) catch |err| switch (err) {
+                    const new_dir = dir.openDirList(entry.name) catch |err| switch (err) {
                         error.NotDir => {
                             if (got_access_denied) {
                                 return error.AccessDenied;
@@ -1222,7 +1222,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.openDir(base.name) catch |err| switch (err) {
+                    var new_dir = top.dir_it.dir.openDirList(base.name) catch |err| switch (err) {
                         error.NameTooLong => unreachable, // no path sep in base.name
                         else => |e| return e,
                     };
@@ -1260,7 +1260,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 Dir.open(dir_path);
+    var dir = try Dir.cwd().openDirList(dir_path);
     errdefer dir.close();
 
     var name_buffer = try std.Buffer.init(allocator, dir_path);
src-self-hosted/main.zig
@@ -715,7 +715,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
     // ) catch |err| switch (err) {
     //     error.IsDir, error.AccessDenied => {
     //         // TODO make event based (and dir.next())
-    //         var dir = try fs.Dir.open(file_path);
+    //         var dir = try fs.Dir.cwd().openDirList(file_path);
     //         defer dir.close();
 
     //         var group = event.Group(FmtError!void).init(fmt.allocator);
src-self-hosted/stage1.zig
@@ -279,7 +279,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []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.Dir.open(file_path);
+            var dir = try fs.Dir.cwd().openDirList(file_path);
             defer dir.close();
 
             var dir_it = dir.iterate();
tools/process_headers.zig
@@ -340,7 +340,7 @@ pub fn main() !void {
             try dir_stack.append(target_include_dir);
 
             while (dir_stack.popOrNull()) |full_dir_name| {
-                var dir = std.fs.Dir.open(full_dir_name) catch |err| switch (err) {
+                var dir = std.fs.Dir.cwd().openDirList(full_dir_name) catch |err| switch (err) {
                     error.FileNotFound => continue :search,
                     error.AccessDenied => continue :search,
                     else => return err,