Skip to content

Commit 53e615b

Browse files
authored
Merge pull request #25993 from squeek502/windows-paths
Teach `std.fs.path` about the wonderful world of Windows paths
2 parents 32dc46a + 822f412 commit 53e615b

File tree

17 files changed

+1699
-776
lines changed

17 files changed

+1699
-776
lines changed

lib/compiler/resinator/compile.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ fn validateSearchPath(path: []const u8) error{BadPathName}!void {
29142914
// (e.g. the NT \??\ prefix, the device \\.\ prefix, etc).
29152915
// Those path types are something of an unavoidable way to
29162916
// still hit unreachable during the openDir call.
2917-
var component_iterator = try std.fs.path.componentIterator(path);
2917+
var component_iterator = std.fs.path.componentIterator(path);
29182918
while (component_iterator.next()) |component| {
29192919
// https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
29202920
if (std.mem.indexOfAny(u8, component.name, "\x00<>:\"|?*") != null) return error.BadPathName;

lib/std/Build/Cache.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ fn findPrefixResolved(cache: *const Cache, resolved_path: []u8) !PrefixedPath {
104104
fn getPrefixSubpath(allocator: Allocator, prefix: []const u8, path: []u8) ![]u8 {
105105
const relative = try fs.path.relative(allocator, prefix, path);
106106
errdefer allocator.free(relative);
107-
var component_iterator = fs.path.NativeComponentIterator.init(relative) catch {
108-
return error.NotASubPath;
109-
};
107+
var component_iterator = fs.path.NativeComponentIterator.init(relative);
110108
if (component_iterator.root() != null) {
111109
return error.NotASubPath;
112110
}

lib/std/Build/Watch/FsEvents.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn setPaths(fse: *FsEvents, gpa: Allocator, steps: []const *std.Build.Step)
167167
}.lessThan);
168168
need_dirs.clearRetainingCapacity();
169169
for (old_dirs) |dir_path| {
170-
var it: std.fs.path.ComponentIterator(.posix, u8) = try .init(dir_path);
170+
var it: std.fs.path.ComponentIterator(.posix, u8) = .init(dir_path);
171171
while (it.next()) |component| {
172172
if (need_dirs.contains(component.path)) {
173173
// this path is '/foo/bar/qux', but '/foo' or '/foo/bar' was already added

lib/std/Io/Dir.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub const MakePathStatus = enum { existed, created };
318318
/// Same as `makePath` except returns whether the path already existed or was
319319
/// successfully created.
320320
pub fn makePathStatus(dir: Dir, io: Io, sub_path: []const u8) MakePathError!MakePathStatus {
321-
var it = try std.fs.path.componentIterator(sub_path);
321+
var it = std.fs.path.componentIterator(sub_path);
322322
var status: MakePathStatus = .existed;
323323
var component = it.last() orelse return error.BadPathName;
324324
while (true) {

lib/std/Io/Threaded.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ fn dirMakeOpenPathWindows(
12101210
w.SYNCHRONIZE | w.FILE_TRAVERSE |
12111211
(if (options.iterate) w.FILE_LIST_DIRECTORY else @as(u32, 0));
12121212

1213-
var it = try std.fs.path.componentIterator(sub_path);
1213+
var it = std.fs.path.componentIterator(sub_path);
12141214
// If there are no components in the path, then create a dummy component with the full path.
12151215
var component: std.fs.path.NativeComponentIterator.Component = it.last() orelse .{
12161216
.name = "",

0 commit comments

Comments
 (0)