mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Avoid deprecated cwd-based functions for opening directories, preferring to open explicitly relative to Dir.cwd().
This commit is contained in:
parent
001334266a
commit
4014a8e4b4
@ -350,7 +350,7 @@ pub fn deleteTree(full_path: []const u8) !void {
|
|||||||
CannotDeleteRootDirectory,
|
CannotDeleteRootDirectory,
|
||||||
}.CannotDeleteRootDirectory;
|
}.CannotDeleteRootDirectory;
|
||||||
|
|
||||||
var dir = try Dir.open(dirname);
|
var dir = try Dir.cwd().openDirList(dirname);
|
||||||
defer dir.close();
|
defer dir.close();
|
||||||
|
|
||||||
return dir.deleteTree(path.basename(full_path));
|
return dir.deleteTree(path.basename(full_path));
|
||||||
@ -1066,7 +1066,7 @@ pub const Dir = struct {
|
|||||||
error.Unexpected,
|
error.Unexpected,
|
||||||
=> |e| return e,
|
=> |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 => {
|
error.NotDir => {
|
||||||
if (got_access_denied) {
|
if (got_access_denied) {
|
||||||
return error.AccessDenied;
|
return error.AccessDenied;
|
||||||
@ -1131,7 +1131,7 @@ pub const Dir = struct {
|
|||||||
=> |e| return e,
|
=> |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 => {
|
error.NotDir => {
|
||||||
if (got_access_denied) {
|
if (got_access_denied) {
|
||||||
return error.AccessDenied;
|
return error.AccessDenied;
|
||||||
@ -1222,7 +1222,7 @@ pub const Walker = struct {
|
|||||||
try self.name_buffer.appendByte(path.sep);
|
try self.name_buffer.appendByte(path.sep);
|
||||||
try self.name_buffer.append(base.name);
|
try self.name_buffer.append(base.name);
|
||||||
if (base.kind == .Directory) {
|
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
|
error.NameTooLong => unreachable, // no path sep in base.name
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
@ -1260,7 +1260,7 @@ pub const Walker = struct {
|
|||||||
pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
|
pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
|
||||||
assert(!mem.endsWith(u8, dir_path, path.sep_str));
|
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();
|
errdefer dir.close();
|
||||||
|
|
||||||
var name_buffer = try std.Buffer.init(allocator, dir_path);
|
var name_buffer = try std.Buffer.init(allocator, dir_path);
|
||||||
|
|||||||
@ -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 ++ "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 io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
|
||||||
try fs.deleteTree("os_test_tmp");
|
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");
|
@panic("expected error");
|
||||||
} else |err| {
|
} else |err| {
|
||||||
expect(err == error.FileNotFound);
|
expect(err == error.FileNotFound);
|
||||||
|
|||||||
@ -715,7 +715,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
|
|||||||
// ) catch |err| switch (err) {
|
// ) catch |err| switch (err) {
|
||||||
// error.IsDir, error.AccessDenied => {
|
// error.IsDir, error.AccessDenied => {
|
||||||
// // TODO make event based (and dir.next())
|
// // 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();
|
// defer dir.close();
|
||||||
|
|
||||||
// var group = event.Group(FmtError!void).init(fmt.allocator);
|
// var group = event.Group(FmtError!void).init(fmt.allocator);
|
||||||
|
|||||||
@ -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) {
|
const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
|
||||||
error.IsDir, error.AccessDenied => {
|
error.IsDir, error.AccessDenied => {
|
||||||
// TODO make event based (and dir.next())
|
// 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();
|
defer dir.close();
|
||||||
|
|
||||||
var dir_it = dir.iterate();
|
var dir_it = dir.iterate();
|
||||||
|
|||||||
@ -340,7 +340,7 @@ pub fn main() !void {
|
|||||||
try dir_stack.append(target_include_dir);
|
try dir_stack.append(target_include_dir);
|
||||||
|
|
||||||
while (dir_stack.popOrNull()) |full_dir_name| {
|
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.FileNotFound => continue :search,
|
||||||
error.AccessDenied => continue :search,
|
error.AccessDenied => continue :search,
|
||||||
else => return err,
|
else => return err,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user