144 Commits

Author SHA1 Message Date
Pat Tullmann
d35bdc8ee7 std/fs/test.zig: Try harder to clean up locking files 2024-01-16 14:19:48 -08:00
Pat Tullmann
c36962bb19 std/fs/test.zig: Factor out the symlink-creation wrappers
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.
2024-01-16 14:19:48 -08:00
Pat Tullmann
95a0e127b3 std/fs/test.zig: quote . and .. in test names
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.
2024-01-16 13:49:00 -08:00
Amir Alawi
4cbf74bd9b
fix std.fs.Dir.makePath silent failure (#16878)
std.fs.dir.makePath silently failed if one of the items in the path already exists. For example:

cwd.makePath("foo/bar/baz")
Silently failing is OK if "bar" is already a directory - this is the intended use of makePath (like mkdir -p). But if bar is a file then the subdirectory baz cannot be created - the end result is that makePath doesn't do anything which should be a detectable error because baz is never created.

The existing code had a TODO comment that did not specifically cover this error, but the solution for this silent failure also accomplishes the TODO task - the code now stats "foo" and returns an appropriate error. The new code also handles potential race condition if "bar" is deleted/permissions changed/etc in between the initial makeDir and statFile calls.
2024-01-08 15:58:14 -05:00
Ryan Liptak
51946f5adc Dir.makePath: Document/test platform differences around .. component handling
Closes #18452
2024-01-05 17:56:31 -08:00
Pat Tullmann
9335529b9b std.fs: Add several more tests for makePath. 2024-01-04 23:20:35 -08:00
Pat Tullmann
1564cb0ab9 std/fs/test.zig: Remove work-around for stat() failures on glibc
glibc variants now support the stat-family of calls correctly, so
this test is safe to include.
2024-01-04 17:12:07 -07:00
Ryan Liptak
70b248497a fs: Add tests for deleteTree not following symlinks
In theory this is part of https://github.com/ziglang/zig/issues/18335, but these tests already pass since deleteTree does not depend on `OpenDirOptions.no_follow` behavior for these test cases:

- `deleteTree` always tries to delete the initial path as a file first, which will succeed on symlinks because `deleteFile` doesn't follow symlinks
- `deleteTree` when iterating a directory will get the type of symlinks as .sym_link, not as .directory (even if the symlink points to a directory), meaning it will never try to open a symlink as a directory.
2023-12-22 13:47:19 +02:00
Ryan Liptak
f5d0664e78 Make 'stat of a symlink' test case not rely on OpenDirOptions.no_follow behavior
The `no_follow` behavior happened to allow opening a file descriptor of a symlink itself on Windows, but that behavior may change in the future. Instead, we implement the opening of the symlink as a file descriptor manually (and per-platform) in the test case.
2023-12-21 17:47:32 -08:00
Ryan Liptak
11a398af3e File.stat: Support detection of Kind.sym_link on Windows
Requires an extra NtQueryInformationFile call when FILE_ATTRIBUTE_REPARSE_POINT is set to determine if it's actually a symlink or some other kind of reparse point (https://learn.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags). This is something that `File.Metadata.kind` was already doing, so the same technique is used in `stat`.

Also, replace the std.os.windows.DeviceIoControl call in `metadata` with NtQueryInformationFile (NtQueryInformationFile is what gets called during kernel32.GetFileInformationByHandleEx with FileAttributeTagInfo, verified using NtTrace).
2023-12-19 23:36:23 -08:00
Andrew Kelley
c95e2e65fa std.fs: extract Dir into separate file 2023-11-22 15:24:57 -07:00
Andrew Kelley
e357550610 update for the std.fs.Dir changes 2023-11-22 15:24:57 -07:00
Andrew Kelley
519ba9bb65 Revert "Merge pull request #12060 from Vexu/IterableDir"
This reverts commit da94227f783ec3c92859c4713b80a668f1183f96, reversing
changes made to 8f943b3d33432a26b7e242c1181e4220ed400501.

I was against this change originally, but decided to approve it to keep
an open mind. After a year of trying it in practice, I firmly believe
that the previous way of doing it was better.
2023-11-22 12:35:33 -07:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Jacob Young
5e83441096 x86_64: implement @divFloor and @mod for i128 2023-10-26 21:45:57 -04:00
Jacob Young
b55377a5ab x86_64: pass more tests
* 128-bit integer multiplication with overflow
 * more instruction encodings used by std inline asm
 * implement the `try_ptr` air instruction
 * follow correct stack frame abi
 * enable full panic handler
 * enable stack traces
2023-10-25 04:28:30 -04:00
Jacob Young
8f69e977f1 x86_64: implement 128-bit builtins
* `@clz`
 * `@ctz`
 * `@popCount`
 * `@byteSwap`
 * `@bitReverse`
 * various encodings used by std
2023-10-23 22:42:18 -04:00
Jacob Young
33483407a2 std: disable failing test 2023-10-22 16:02:33 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing
changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
0c99ba1eab
Merge pull request #17637 from jacobly0/x86_64-test-std
x86_64: start to enable `test-std` and `test-compiler-rt` testing
2023-10-22 08:06:47 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Qusai Hroub
f6a6cdbba3 std.fs.Dir.makeOpenPath: optimize when path already exists
Uses a single NtCreateFile syscall on windows.

Closes #12474. Thanks to @joedavis and @matu3ba.
2023-10-18 20:36:03 -07:00
Andrew Kelley
877393d17a std.fs: fix relative symbolic links on Windows
closes #17564
2023-10-17 06:27:07 -04:00
Andrew Kelley
1456f95b3c std: disable flaky test on aarch64-windows
tracked by #17134
2023-10-16 16:13:46 -07:00
Pat Tullmann
57874ce619
lib/std/fs/test.zig: cleanup (#17443)
* fs/test.zig: use arena allocator more consistently

* fs/test.zig: remove unnecessary type information

Zig can (now?) implicitly cast a `&.{ "foo"}` when passed to
`fs.path.join()`, so the `[_][]const u8` is unnecessary.

* fs/test.zig: Use fs.path.join() for longer paths

Replace long path constructions (that use several "++ path_sep ++")
with a single call to `fs.path.join`.  Seems more readable to me.

* fs/test.zig: fmt
2023-10-09 16:44:14 +03:00
Ryan Liptak
742030a8f2 fs tests: Skip UNC path types in Dir.rename tests
Follow up to https://github.com/ziglang/zig/pull/17136. The `Dir.rename files` test has now also been seen to fail in CI, so now all rename tests are skipped for the UNC path type. This is a heavy handed approach to hopefully get rid of any flakiness related to rename & UNC paths. See https://github.com/ziglang/zig/issues/17134
2023-09-14 16:30:41 +03:00
Ryan Liptak
89ea67aee2 Disable flaky part of Dir.rename directories test on Windows
See https://github.com/ziglang/zig/issues/17134
2023-09-13 03:46:00 -04:00
Ryan Liptak
01f9cdd21a Temporarily disable Dir.statFile test when linking glibc
See https://github.com/ziglang/zig/issues/17034
2023-08-31 18:01:15 -07:00
Ryan Liptak
f46008c1d8 Fix Dir.statFile for WASI when linking libc
`statFile` now only uses `os.fstatatWasi` when not linking libc, matching the pattern used throughout other `Dir` functions. This fixes the compilation error: `error: struct 'c.wasi.Stat' has no member named 'fromFilestat'` (which the added test would have failed with)
2023-08-31 14:07:15 -07:00
Ryan Liptak
3dd439030c fs tests: Use 127.0.0.1 instead of localhost as the server in UNC transformation
In theory, localhost could be mapped to a different address via the LMHOSTS file, so using 127.0.0.1 should remove that potential wrinkle and allow the drive-absolute -> UNC transformation to work on any(?) setup.

Also print the error name to ensure it gets printed in CI (aarch64-windows ReleaseSmall seemed not to print the error in the last intermittent UNC failure)
2023-08-18 12:21:54 -07:00
Andrew Kelley
8c1329b222
Merge pull request #16847 from squeek502/fs-fixes
`std.fs`: Improve tests and fix some bugs that were uncovered
2023-08-17 12:15:51 -07:00
Ryan Liptak
8c8f3cbd43 fs tests: Update some testing.expect calls to use the more specific expect functions 2023-08-17 00:59:19 -07:00
Ryan Liptak
8f5f1ff25a fs tests: Test multiple different path types in most tests
(which path types will depend on which the target supports)
2023-08-17 00:59:19 -07:00
Michael Dusan
3eedaab731
bsd: std.c.fs: skip test w/ getFdPath in calltree 2023-08-15 17:29:35 -04:00
Ryan Liptak
3e69115784 Do not skip fs.Dir.access test on WASI 2023-08-15 14:00:35 -07:00
Andrew Kelley
35b85d3ba5
Merge pull request #16783 from squeek502/fs-too-many-parent-dirs
Windows: Fix `TooManyParentDirs` handling for paths that shouldn't be cwd-relative
2023-08-12 10:38:31 -07:00
Ryan Liptak
7e542e788c fs tests: Add a 'non-cwd .. parent' test 2023-08-11 18:58:40 -07:00
Ryan Liptak
a190582b26 fs.Dir.realpathW: Reduce the number of OpenFile calls for directories
`.filter = .any` can be used here to remove an unnecessary extra OpenFile call when getting the path of a directory
2023-08-10 13:25:14 -07:00
Ryan Liptak
21ecb1ba0f Consolidate 'delete a read-only file on windows' test cases
These two tests can't be disambiguated at comptime, since the filesystem that the test is running on also matters for whether or not POSIX_SEMANTICS / IGNORE_READONLY_ATTRIBUTE can actually be used (since they are only supported on NTFS).
2023-07-23 01:26:26 -07:00
Andrew Kelley
e3736baddb
Merge pull request #15501 from matu3ba/win_rmwithposix
std.windows: use posix semantics to delete files, if available
2023-06-17 14:21:15 -07:00
Linus Groh
ba35eeb417 std.fs.file: Rename File.Lock enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00
Jan Philipp Hafer
7594d2c097 address review by user @squeek502 2023-05-01 18:22:28 +02:00
xEgoist
1a455b2dd8 test: Fix windows_spawn tmp directory cleanup
On Windows, a directory that's set as the current working directory is
not allowed to be removed. This can cause error on `deleteTree` if the
CWD is set to the file to be removed and will cause `error.FileBusy`.
However, due to `tmp.cleanup()` ignoring the errors, the folder removal error will
be ignored. The only test violating this is `windows_spawn`. As a
solution, setting the parent directory to be the CWD before deletion
will allow the cleanup to pass.
2023-04-27 11:01:02 +03:00
xEgoist
55b2456c11 fs: add test for Windows ready-only file deletion.
Deleting a read-only file should result in `AccessDenied` (`CANNOT_DELETE`).

Note: This test was observed to fail when the file is closed then reopened
before the change in permission due to the absence of
`FILE_WRITE_ATTRIBUTES` when re-opened. (see #15316).
2023-04-18 05:27:28 -05:00
xEgoist
73c04d4b28 fs: Re-enable non-empty dir test on windows 2023-04-16 15:18:15 -05:00
Andrew Kelley
a1058dd27b fix std.fs unit test to not be racey 2023-03-15 10:48:15 -07:00
Andrew Kelley
02f5d2673f Revert "Merge pull request #14661 from evacchi/zig-wasi-preopens"
This reverts commit 772a0eb68ac95b7e24508580499b49872fdb541f, reversing
changes made to 0bb178bbb2451238a326c6e916ecf38fbc34cab1.

This needs a rebase against master branch - it has build-breaking merge
conflicts. I also added a "changes requested" review on the original
pull request.
2023-02-19 09:40:55 -07:00
Edoardo Vacchi
a250af5a51 wasi: add Preopens.findDir, update tests to preopen `/tmp'
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-02-18 21:41:26 +01:00