-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Related to #4605, #4655, #4658
From IRC (talking about #4655):
<daurnimator>squeek502_: so realpath is inherently racy
<daurnimator>you need to do it inside of theopencall.
<daurnimator>(on windows essentially everything is done by opening)
<daurnimator>e.g. to delete a file you open a file; set a flag that says "delete this file when I close it" and then close the file handle
<squeek502_>which open call?
<squeek502_>the open within readFileAlloc?
<daurnimator>yep
<squeek502_>so you're saying readFileAlloc should handle the path resolution on its own?
<daurnimator>yes
<squeek502_>it does seem like there needs to be a decision about what's valid to pass to the various fs functions, its unclear if.\fileis expected to always be a valid input to any fs function on Windows or if it should be resolved before certain fs functions
<daurnimator>indeed
In the following test code:
const std = @import("std");
test "windows open file" {
var first = try std.fs.cwd().openFile("test.zig", .{});
first.close();
var second = try std.fs.cwd().openFile(".\\test.zig", .{});
second.close();
}If test.zig exists, the first open succeeds, but the second fails, even though they would resolve to the same path. This is because the file path is never resolved and when .\test.zig is passed as the ObjectName to NtCreateFile, it errors with STATUS_OBJECT_NAME_INVALID. The same thing happens if a path with .. is given as the ObjectName.
It's unclear where this resolution should happen, exactly, and the current fs docs don't specify which types of paths each function accepts.