| ... | ... | @@ -2,7 +2,6 @@ const Path = @This(); |
| 2 | 2 | |
| 3 | 3 | const std = @import("../../std.zig"); |
| 4 | 4 | const Io = std.Io; |
| 5 | | const fs = std.fs; |
| 6 | 5 | const assert = std.debug.assert; |
| 7 | 6 | const Allocator = std.mem.Allocator; |
| 8 | 7 | const Cache = std.Build.Cache; |
| ... | ... | @@ -33,13 +32,13 @@ pub fn join(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Pat |
| 33 | 32 | if (p.sub_path.len == 0) &.{sub_path} else &.{ p.sub_path, sub_path }; |
| 34 | 33 | return .{ |
| 35 | 34 | .root_dir = p.root_dir, |
| 36 | | .sub_path = try fs.path.join(arena, parts), |
| 35 | .sub_path = try Io.Dir.path.join(arena, parts), |
| 37 | 36 | }; |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | pub fn resolvePosix(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Path { |
| 41 | 40 | if (sub_path.len == 0) return p; |
| 42 | | const new_sub_path = try fs.path.resolvePosix(arena, &.{ p.sub_path, sub_path }); |
| 41 | const new_sub_path = try Io.Dir.path.resolvePosix(arena, &.{ p.sub_path, sub_path }); |
| 43 | 42 | return .{ |
| 44 | 43 | .root_dir = p.root_dir, |
| 45 | 44 | // Use "" instead of "." to represent `root_dir` itself. |
| ... | ... | @@ -60,9 +59,9 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro |
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.OpenFileOptions) !Io.File { |
| 63 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 62 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 64 | 63 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 65 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 64 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 66 | 65 | p.sub_path, sub_path, |
| 67 | 66 | }) catch return error.NameTooLong; |
| 68 | 67 | }; |
| ... | ... | @@ -75,19 +74,19 @@ pub fn openDir( |
| 75 | 74 | sub_path: []const u8, |
| 76 | 75 | args: Io.Dir.OpenOptions, |
| 77 | 76 | ) Io.Dir.OpenError!Io.Dir { |
| 78 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 77 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 79 | 78 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 80 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 79 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 81 | 80 | p.sub_path, sub_path, |
| 82 | 81 | }) catch return error.NameTooLong; |
| 83 | 82 | }; |
| 84 | 83 | return p.root_dir.handle.openDir(io, joined_path, args); |
| 85 | 84 | } |
| 86 | 85 | |
| 87 | | pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.OpenOptions) !Io.Dir { |
| 88 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 86 | pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.CreateDirPathOpenOptions) !Io.Dir { |
| 87 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 89 | 88 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 90 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 89 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 91 | 90 | p.sub_path, sub_path, |
| 92 | 91 | }) catch return error.NameTooLong; |
| 93 | 92 | }; |
| ... | ... | @@ -95,9 +94,9 @@ pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.Ope |
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat { |
| 98 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 97 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 99 | 98 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 100 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 99 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 101 | 100 | p.sub_path, sub_path, |
| 102 | 101 | }) catch return error.NameTooLong; |
| 103 | 102 | }; |
| ... | ... | @@ -108,21 +107,21 @@ pub fn atomicFile( |
| 108 | 107 | p: Path, |
| 109 | 108 | io: Io, |
| 110 | 109 | sub_path: []const u8, |
| 111 | | options: Io.Dir.AtomicFileOptions, |
| 112 | | buf: *[fs.max_path_bytes]u8, |
| 113 | | ) !fs.AtomicFile { |
| 110 | options: Io.Dir.CreateFileAtomicOptions, |
| 111 | buf: *[Io.Dir.max_path_bytes]u8, |
| 112 | ) !Io.File.Atomic { |
| 114 | 113 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 115 | | break :p std.fmt.bufPrint(buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 114 | break :p std.fmt.bufPrint(buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 116 | 115 | p.sub_path, sub_path, |
| 117 | 116 | }) catch return error.NameTooLong; |
| 118 | 117 | }; |
| 119 | | return p.root_dir.handle.atomicFile(io, joined_path, options); |
| 118 | return p.root_dir.handle.createFileAtomic(io, joined_path, options); |
| 120 | 119 | } |
| 121 | 120 | |
| 122 | 121 | pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void { |
| 123 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 122 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 124 | 123 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 125 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 124 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 126 | 125 | p.sub_path, sub_path, |
| 127 | 126 | }) catch return error.NameTooLong; |
| 128 | 127 | }; |
| ... | ... | @@ -130,9 +129,9 @@ pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions |
| 130 | 129 | } |
| 131 | 130 | |
| 132 | 131 | pub fn createDirPath(p: Path, io: Io, sub_path: []const u8) !void { |
| 133 | | var buf: [fs.max_path_bytes]u8 = undefined; |
| 132 | var buf: [Io.Dir.max_path_bytes]u8 = undefined; |
| 134 | 133 | const joined_path = if (p.sub_path.len == 0) sub_path else p: { |
| 135 | | break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ |
| 134 | break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{ |
| 136 | 135 | p.sub_path, sub_path, |
| 137 | 136 | }) catch return error.NameTooLong; |
| 138 | 137 | }; |
| ... | ... | @@ -154,7 +153,7 @@ pub fn fmtEscapeString(path: Path) std.fmt.Alt(Path, formatEscapeString) { |
| 154 | 153 | pub fn formatEscapeString(path: Path, writer: *Io.Writer) Io.Writer.Error!void { |
| 155 | 154 | if (path.root_dir.path) |p| { |
| 156 | 155 | try std.zig.stringEscape(p, writer); |
| 157 | | if (path.sub_path.len > 0) try std.zig.stringEscape(fs.path.sep_str, writer); |
| 156 | if (path.sub_path.len > 0) try std.zig.stringEscape(Io.Dir.path.sep_str, writer); |
| 158 | 157 | } |
| 159 | 158 | if (path.sub_path.len > 0) { |
| 160 | 159 | try std.zig.stringEscape(path.sub_path, writer); |
| ... | ... | @@ -170,7 +169,7 @@ pub fn fmtEscapeChar(path: Path) std.fmt.Alt(Path, formatEscapeChar) { |
| 170 | 169 | pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void { |
| 171 | 170 | if (path.root_dir.path) |p| { |
| 172 | 171 | for (p) |byte| try std.zig.charEscape(byte, writer); |
| 173 | | if (path.sub_path.len > 0) try writer.writeByte(fs.path.sep); |
| 172 | if (path.sub_path.len > 0) try writer.writeByte(Io.Dir.path.sep); |
| 174 | 173 | } |
| 175 | 174 | if (path.sub_path.len > 0) { |
| 176 | 175 | for (path.sub_path) |byte| try std.zig.charEscape(byte, writer); |
| ... | ... | @@ -178,14 +177,14 @@ pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void { |
| 178 | 177 | } |
| 179 | 178 | |
| 180 | 179 | pub fn format(self: Path, writer: *Io.Writer) Io.Writer.Error!void { |
| 181 | | if (fs.path.isAbsolute(self.sub_path)) { |
| 180 | if (Io.Dir.path.isAbsolute(self.sub_path)) { |
| 182 | 181 | try writer.writeAll(self.sub_path); |
| 183 | 182 | return; |
| 184 | 183 | } |
| 185 | 184 | if (self.root_dir.path) |p| { |
| 186 | 185 | try writer.writeAll(p); |
| 187 | 186 | if (self.sub_path.len > 0) { |
| 188 | | try writer.writeAll(fs.path.sep_str); |
| 187 | try writer.writeAll(Io.Dir.path.sep_str); |
| 189 | 188 | try writer.writeAll(self.sub_path); |
| 190 | 189 | } |
| 191 | 190 | return; |
| ... | ... | @@ -210,18 +209,18 @@ pub fn subPathOrDot(self: Path) []const u8 { |
| 210 | 209 | } |
| 211 | 210 | |
| 212 | 211 | pub fn stem(p: Path) []const u8 { |
| 213 | | return fs.path.stem(p.sub_path); |
| 212 | return Io.Dir.path.stem(p.sub_path); |
| 214 | 213 | } |
| 215 | 214 | |
| 216 | 215 | pub fn dirname(p: Path) ?Path { |
| 217 | 216 | return .{ |
| 218 | 217 | .root_dir = p.root_dir, |
| 219 | | .sub_path = fs.path.dirname(p.subPathOpt() orelse return null) orelse "", |
| 218 | .sub_path = Io.Dir.path.dirname(p.subPathOpt() orelse return null) orelse "", |
| 220 | 219 | }; |
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | pub fn basename(p: Path) []const u8 { |
| 224 | | return fs.path.basename(p.sub_path); |
| 223 | return Io.Dir.path.basename(p.sub_path); |
| 225 | 224 | } |
| 226 | 225 | |
| 227 | 226 | /// Useful to make `Path` a key in `std.ArrayHashMap`. |