authorgravatar for gereeter+code@gmail.comJonathan S <gereeter+code@gmail.com> 2019-11-22 16:32:50-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-25 23:46:48-05:00
log4014a8e4b44bad5aca896ce0fdf120ef4212fc8d
tree905180f165743072aa1409199ae06897474120ff
parent001334266a0f6d0d7da4e0eba5b5e317456a39ff

Avoid deprecated cwd-based functions for opening directories, preferring to open explicitly relative to `Dir.cwd()`.


5 files changed, 9 insertions(+), 9 deletions(-)

lib/std/fs.zig+5-5
...@@ -350,7 +350,7 @@ pub fn deleteTree(full_path: []const u8) !void {...@@ -350,7 +350,7 @@ pub fn deleteTree(full_path: []const u8) !void {
350 CannotDeleteRootDirectory,350 CannotDeleteRootDirectory,
351 }.CannotDeleteRootDirectory;351 }.CannotDeleteRootDirectory;
352352
353 var dir = try Dir.open(dirname);353 var dir = try Dir.cwd().openDirList(dirname);
354 defer dir.close();354 defer dir.close();
355355
356 return dir.deleteTree(path.basename(full_path));356 return dir.deleteTree(path.basename(full_path));
...@@ -1066,7 +1066,7 @@ pub const Dir = struct {...@@ -1066,7 +1066,7 @@ pub const Dir = struct {
1066 error.Unexpected,1066 error.Unexpected,
1067 => |e| return e,1067 => |e| return e,
1068 }1068 }
1069 var dir = self.openDir(sub_path) catch |err| switch (err) {1069 var dir = self.openDirList(sub_path) catch |err| switch (err) {
1070 error.NotDir => {1070 error.NotDir => {
1071 if (got_access_denied) {1071 if (got_access_denied) {
1072 return error.AccessDenied;1072 return error.AccessDenied;
...@@ -1131,7 +1131,7 @@ pub const Dir = struct {...@@ -1131,7 +1131,7 @@ pub const Dir = struct {
1131 => |e| return e,1131 => |e| return e,
1132 }1132 }
11331133
1134 const new_dir = dir.openDir(entry.name) catch |err| switch (err) {1134 const new_dir = dir.openDirList(entry.name) catch |err| switch (err) {
1135 error.NotDir => {1135 error.NotDir => {
1136 if (got_access_denied) {1136 if (got_access_denied) {
1137 return error.AccessDenied;1137 return error.AccessDenied;
...@@ -1222,7 +1222,7 @@ pub const Walker = struct {...@@ -1222,7 +1222,7 @@ pub const Walker = struct {
1222 try self.name_buffer.appendByte(path.sep);1222 try self.name_buffer.appendByte(path.sep);
1223 try self.name_buffer.append(base.name);1223 try self.name_buffer.append(base.name);
1224 if (base.kind == .Directory) {1224 if (base.kind == .Directory) {
1225 var new_dir = top.dir_it.dir.openDir(base.name) catch |err| switch (err) {1225 var new_dir = top.dir_it.dir.openDirList(base.name) catch |err| switch (err) {
1226 error.NameTooLong => unreachable, // no path sep in base.name1226 error.NameTooLong => unreachable, // no path sep in base.name
1227 else => |e| return e,1227 else => |e| return e,
1228 };1228 };
...@@ -1260,7 +1260,7 @@ pub const Walker = struct {...@@ -1260,7 +1260,7 @@ pub const Walker = struct {
1260pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {1260pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
1261 assert(!mem.endsWith(u8, dir_path, path.sep_str));1261 assert(!mem.endsWith(u8, dir_path, path.sep_str));
12621262
1263 var dir = try Dir.open(dir_path);1263 var dir = try Dir.cwd().openDirList(dir_path);
1264 errdefer dir.close();1264 errdefer dir.close();
12651265
1266 var name_buffer = try std.Buffer.init(allocator, dir_path);1266 var name_buffer = try std.Buffer.init(allocator, dir_path);
lib/std/os/test.zig+1-1
...@@ -20,7 +20,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -20,7 +20,7 @@ test "makePath, put some files in it, deleteTree" {
20 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");20 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
22 try fs.deleteTree("os_test_tmp");22 try fs.deleteTree("os_test_tmp");
23 if (fs.Dir.open("os_test_tmp")) |dir| {23 if (fs.Dir.cwd().openDirTraverse("os_test_tmp")) |dir| {
24 @panic("expected error");24 @panic("expected error");
25 } else |err| {25 } else |err| {
26 expect(err == error.FileNotFound);26 expect(err == error.FileNotFound);
src-self-hosted/main.zig+1-1
...@@ -715,7 +715,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -715,7 +715,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
715 // ) catch |err| switch (err) {715 // ) catch |err| switch (err) {
716 // error.IsDir, error.AccessDenied => {716 // error.IsDir, error.AccessDenied => {
717 // // TODO make event based (and dir.next())717 // // TODO make event based (and dir.next())
718 // var dir = try fs.Dir.open(file_path);718 // var dir = try fs.Dir.cwd().openDirList(file_path);
719 // defer dir.close();719 // defer dir.close();
720720
721 // var group = event.Group(FmtError!void).init(fmt.allocator);721 // var group = event.Group(FmtError!void).init(fmt.allocator);
src-self-hosted/stage1.zig+1-1
...@@ -279,7 +279,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -279,7 +279,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
279 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {279 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
280 error.IsDir, error.AccessDenied => {280 error.IsDir, error.AccessDenied => {
281 // TODO make event based (and dir.next())281 // TODO make event based (and dir.next())
282 var dir = try fs.Dir.open(file_path);282 var dir = try fs.Dir.cwd().openDirList(file_path);
283 defer dir.close();283 defer dir.close();
284284
285 var dir_it = dir.iterate();285 var dir_it = dir.iterate();
tools/process_headers.zig+1-1
...@@ -340,7 +340,7 @@ pub fn main() !void {...@@ -340,7 +340,7 @@ pub fn main() !void {
340 try dir_stack.append(target_include_dir);340 try dir_stack.append(target_include_dir);
341341
342 while (dir_stack.popOrNull()) |full_dir_name| {342 while (dir_stack.popOrNull()) |full_dir_name| {
343 var dir = std.fs.Dir.open(full_dir_name) catch |err| switch (err) {343 var dir = std.fs.Dir.cwd().openDirList(full_dir_name) catch |err| switch (err) {
344 error.FileNotFound => continue :search,344 error.FileNotFound => continue :search,
345 error.AccessDenied => continue :search,345 error.AccessDenied => continue :search,
346 else => return err,346 else => return err,