authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-07-09 22:36:38+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-09 13:36:38-07:00
log0cc42d090fefcdd10ab64f6ae484404a6c6a710e
tree47520f97e9312d70440eb4d6b0ebc95b3f9a4fc5
parentc1e7eb738934399737b3a8452ad9b68bb26805d3
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.fs.Dir: Rename OpenDirOptions to OpenOptions (#20542)

* std.fs.Dir: Rename OpenDirOptions to OpenOptions https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces * std.fs.Dir: Add deprecated alias `OpenDirOptions`

5 files changed, 17 insertions(+), 14 deletions(-)

lib/std/Build/Cache/Path.zig+1-1
......@@ -58,7 +58,7 @@ pub fn openFile(
5858 return p.root_dir.handle.openFile(joined_path, flags);
5959}
6060
61pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.Dir.OpenDirOptions) !fs.Dir {
61pub fn makeOpenPath(p: Path, sub_path: []const u8, opts: fs.Dir.OpenOptions) !fs.Dir {
6262 var buf: [fs.max_path_bytes]u8 = undefined;
6363 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
6464 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
lib/std/fs.zig+3-3
......@@ -278,18 +278,18 @@ pub fn defaultWasiCwd() std.os.wasi.fd_t {
278278/// On Windows, `absolute_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/).
279279/// On WASI, `absolute_path` should be encoded as valid UTF-8.
280280/// On other platforms, `absolute_path` is an opaque sequence of bytes with no particular encoding.
281pub fn openDirAbsolute(absolute_path: []const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir {
281pub fn openDirAbsolute(absolute_path: []const u8, flags: Dir.OpenOptions) File.OpenError!Dir {
282282 assert(path.isAbsolute(absolute_path));
283283 return cwd().openDir(absolute_path, flags);
284284}
285285
286286/// Same as `openDirAbsolute` but the path parameter is null-terminated.
287pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenDirOptions) File.OpenError!Dir {
287pub fn openDirAbsoluteZ(absolute_path_c: [*:0]const u8, flags: Dir.OpenOptions) File.OpenError!Dir {
288288 assert(path.isAbsoluteZ(absolute_path_c));
289289 return cwd().openDirZ(absolute_path_c, flags);
290290}
291291/// Same as `openDirAbsolute` but the path parameter is null-terminated.
292pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenDirOptions) File.OpenError!Dir {
292pub fn openDirAbsoluteW(absolute_path_c: [*:0]const u16, flags: Dir.OpenOptions) File.OpenError!Dir {
293293 assert(path.isAbsoluteWindowsW(absolute_path_c));
294294 return cwd().openDirW(absolute_path_c, flags);
295295}
lib/std/fs/Dir.zig+11-8
......@@ -740,7 +740,7 @@ pub const Walker = struct {
740740
741741/// Recursively iterates over a directory.
742742///
743/// `self` must have been opened with `OpenDirOptions{.iterate = true}`.
743/// `self` must have been opened with `OpenOptions{.iterate = true}`.
744744///
745745/// `Walker.deinit` releases allocated memory and directory handles.
746746///
......@@ -1233,7 +1233,7 @@ fn makeOpenPathAccessMaskW(self: Dir, sub_path: []const u8, access_mask: u32, no
12331233/// On Windows, `sub_path` should be encoded as [WTF-8](https://simonsapin.github.io/wtf-8/).
12341234/// On WASI, `sub_path` should be encoded as valid UTF-8.
12351235/// On other platforms, `sub_path` is an opaque sequence of bytes with no particular encoding.
1236pub fn makeOpenPath(self: Dir, sub_path: []const u8, open_dir_options: OpenDirOptions) (MakeError || OpenError || StatFileError)!Dir {
1236pub fn makeOpenPath(self: Dir, sub_path: []const u8, open_dir_options: OpenOptions) (MakeError || OpenError || StatFileError)!Dir {
12371237 return switch (native_os) {
12381238 .windows => {
12391239 const w = windows;
......@@ -1393,7 +1393,10 @@ pub fn setAsCwd(self: Dir) !void {
13931393 try posix.fchdir(self.fd);
13941394}
13951395
1396pub const OpenDirOptions = struct {
1396/// Deprecated: use `OpenOptions`
1397pub const OpenDirOptions = OpenOptions;
1398
1399pub const OpenOptions = struct {
13971400 /// `true` means the opened directory can be used as the `Dir` parameter
13981401 /// for functions which operate based on an open directory handle. When `false`,
13991402 /// such operations are Illegal Behavior.
......@@ -1415,7 +1418,7 @@ pub const OpenDirOptions = struct {
14151418/// On WASI, `sub_path` should be encoded as valid UTF-8.
14161419/// On other platforms, `sub_path` is an opaque sequence of bytes with no particular encoding.
14171420/// Asserts that the path parameter has no null bytes.
1418pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
1421pub fn openDir(self: Dir, sub_path: []const u8, args: OpenOptions) OpenError!Dir {
14191422 switch (native_os) {
14201423 .windows => {
14211424 const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
......@@ -1473,7 +1476,7 @@ pub fn openDir(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!
14731476}
14741477
14751478/// Same as `openDir` except the parameter is null-terminated.
1476pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
1479pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenOptions) OpenError!Dir {
14771480 switch (native_os) {
14781481 .windows => {
14791482 const sub_path_w = try windows.cStrToPrefixedFileW(self.fd, sub_path_c);
......@@ -1530,7 +1533,7 @@ pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) Open
15301533
15311534/// Same as `openDir` except the path parameter is WTF-16 LE encoded, NT-prefixed.
15321535/// This function asserts the target OS is Windows.
1533pub fn openDirW(self: Dir, sub_path_w: [*:0]const u16, args: OpenDirOptions) OpenError!Dir {
1536pub fn openDirW(self: Dir, sub_path_w: [*:0]const u16, args: OpenOptions) OpenError!Dir {
15341537 const w = windows;
15351538 // TODO remove some of these flags if args.access_sub_paths is false
15361539 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
......@@ -2650,7 +2653,7 @@ pub const ChmodError = File.ChmodError;
26502653/// The process must have the correct privileges in order to do this
26512654/// successfully, or must have the effective user ID matching the owner
26522655/// of the directory. Additionally, the directory must have been opened
2653/// with `OpenDirOptions{ .iterate = true }`.
2656/// with `OpenOptions{ .iterate = true }`.
26542657pub fn chmod(self: Dir, new_mode: File.Mode) ChmodError!void {
26552658 const file: File = .{ .handle = self.fd };
26562659 try file.chmod(new_mode);
......@@ -2660,7 +2663,7 @@ pub fn chmod(self: Dir, new_mode: File.Mode) ChmodError!void {
26602663/// The process must have the correct privileges in order to do this
26612664/// successfully. The group may be changed by the owner of the directory to
26622665/// any group of which the owner is a member. Additionally, the directory
2663/// must have been opened with `OpenDirOptions{ .iterate = true }`. If the
2666/// must have been opened with `OpenOptions{ .iterate = true }`. If the
26642667/// owner or group is specified as `null`, the ID is not changed.
26652668pub fn chown(self: Dir, owner: ?File.Uid, group: ?File.Gid) ChownError!void {
26662669 const file: File = .{ .handle = self.fd };
lib/std/posix.zig+1-1
......@@ -493,7 +493,7 @@ pub fn fchown(fd: fd_t, owner: ?uid_t, group: ?gid_t) FChownError!void {
493493 switch (errno(res)) {
494494 .SUCCESS => return,
495495 .INTR => continue,
496 .BADF => unreachable, // Can be reached if the fd refers to a directory opened without `OpenDirOptions{ .iterate = true }`
496 .BADF => unreachable, // Can be reached if the fd refers to a directory opened without `Dir.OpenOptions{ .iterate = true }`
497497
498498 .FAULT => unreachable,
499499 .INVAL => unreachable,
lib/std/testing.zig+1-1
......@@ -558,7 +558,7 @@ pub const TmpDir = struct {
558558 }
559559};
560560
561pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
561pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir {
562562 var random_bytes: [TmpDir.random_bytes_count]u8 = undefined;
563563 std.crypto.random.bytes(&random_bytes);
564564 var sub_path: [TmpDir.sub_path_len]u8 = undefined;