Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.fs: tests for makePath and symlinks #17499

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

rootbeer
Copy link
Contributor

@rootbeer rootbeer commented Oct 12, 2023

Refactor tests around makePath and symlinks.

@squeek502
Copy link
Collaborator

squeek502 commented Oct 12, 2023

This is a duplicate of #16878. I like #16878's implementation better but more tests are always good.

Both are somewhat blocked by #17034

@rootbeer
Copy link
Contributor Author

Thanks for the links, I'm happy to put my test cases into #16878 if you'd rather see that fix. I find the flow control with the inline named block harder to reason about ... and its not clear to me that #16878 handles the case where statFile() returns FileNotFound (which I believe is the error returned from statFile() when a dangling symlink is found). I guess this would be made clear one way or another by the test cases. :)

After fixing some embarassing fmt and wasi platform errors, I'm still seeing an odd (but consistent) failure on aarch64-windows. I'll look into those. I guess I need to figure out how to run tests locally.

I'll try digging into the fstatat bug a bit too. Mostly a good exercise for me to learn about the syscall wrapping works in Zig (vs. actually being finding the root cause), but I'll update the PR with anything I learn.

@squeek502
Copy link
Collaborator

squeek502 commented Oct 12, 2023

the case where statFile() returns FileNotFound

I don't think we can say for certain that FileNotFound from statFile is a dangling symlink, as it's possible that e.g. a totally normal directory existed during the makeDir call but was deleted before the statFile call.

@rootbeer
Copy link
Contributor Author

rootbeer commented Oct 13, 2023

I don't think we can say for certain that FileNotFound from statFile is a dangling symlink, as it's possible that e.g. a totally normal directory existed during the makeDir call but was deleted before the statFile call.

Ah, yeah, it could be a race with a parallel delete. Is that sort of race condition something makePath() should worry about though? I'm not sure that the behavior of this change (failing the makePath() operation) is unacceptable. Wouldn't that happen anyway in many cases? E.g., if I makePath("a/b/c"), and something else deletes "b" at just the wrong time, the makePath() attempt to create "c" would fail obtusely?

I can tone down my overconfident comment about the FileNotFound a bit though. You're right its not the only possibility, but its probably good enough...

@squeek502
Copy link
Collaborator

squeek502 commented Oct 13, 2023

I'm just saying converting FileNotFound from statFile in makePath to NotDir is not always the correct thing to do. Returning the error as FileNotFound seems like the better option (which is how it's handled in #16878)

@squeek502
Copy link
Collaborator

squeek502 commented Jan 5, 2024

I've cherry-picked most of the tests from this PR into #18453.

#17702 being merged means that both this and #16878 no longer need to skip any tests when targeting GNU libc (excellent work on that, btw, it'll be a huge relief to not have to worry about stat calls breaking things).

Note that neither this nor #16878 is currently sufficient to resolve #17330, since resolving it on Windows is going to take a bit more effort (see #17330 (comment)).

So, my current thoughts are:

Let me know if that sounds okay to you.

@rootbeer
Copy link
Contributor Author

rootbeer commented Jan 5, 2024

Sounds like a good plan. Once the dust settles a bit, I'll trim this down to the test dangling symlink test. Thanks for getting the other tests merged and isolating the Windows problems!

The test runner uses "." in its output between the test module and the
test name, so quote the leading '.' in these test names to make them
easier to read.
Because creation of a symlink can fail on Windows with an Access Denied
error (https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links)
any tests that need a symbolic link "skip" if they run into this problem.

This change factors out a "setupSymbolicLink()" routine to make this
clearer, a bit tighter, and easier to use in future tests.

I also collapsed the "symlink in parent directory" test into the existing
"Dir.readlink" test, because the latter uses the more comprehensive
testWithAllSupportedPathTypes wrapper.
Create a dangling symlink and check that statFile works with it.
@rootbeer rootbeer force-pushed the makepath-dangling-symlink branch from 2ec2b12 to ff56138 Compare January 16, 2024 22:21
@rootbeer
Copy link
Contributor Author

@squeek502 Can you give this a quick look over? All that really remained from this CL after separating out the makepath fix and the already-present tests was a bunch of misc cleanup. Add to that some cleanup I inserted when trying to get these tests to pass on Wine (that's not happening). Not sure if I should resurrect this on this PR, or close this PR and start a new one. Thanks!

@squeek502
Copy link
Collaborator

squeek502 commented Jan 17, 2024

Test changes look good to me, I'd say mark this as ready for review and it can be merged as-is. We can tackle fixing #17330 in a separate PR.

@rootbeer rootbeer marked this pull request as ready for review January 18, 2024 01:13
@rootbeer rootbeer changed the title std.fs: makePath should handle dangling symlinks gracefully std.fs: tests for makePath and symlinks Jan 18, 2024
@andrewrk andrewrk merged commit 22b9d89 into ziglang:master Jan 18, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants