315 Commits

Author SHA1 Message Date
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
zooster
bc8e1e1de4
Improvements to docs and text
* docs(std.math): elaborate on difference between absCast and absInt

* docs(std.rand.Random.weightedIndex): elaborate on likelihood

I think this makes it easier to understand.

* langref: add small reminder

* docs(std.fs.path.extension): brevity

* docs(std.bit_set.StaticBitSet): mention the specific types

* std.debug.TTY: explain what purpose this struct serves

This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging.

* langref(package listing): brevity

* langref: explain what exactly `threadlocal` causes to happen

* std.array_list: link between swapRemove and orderedRemove

Maybe this can serve as a TLDR and make it easier to decide.

* PrefetchOptions.locality: clarify docs that this is a range

This confused me previously and I thought I can only use either 0 or 3.

* fix typos and more

* std.builtin.CallingConvention: document some CCs

* langref: explain possibly cryptic names

I think it helps knowing what exactly these acronyms (@clz and @ctz) and
abbreviations (@popCount) mean.

* variadic function error: add missing preposition

* std.fmt.format docs: nicely hyphenate

* help menu: say what to optimize for

I think this is slightly more specific than just calling it
"optimizations". These are speed optimizations. I used the word
"performance" here.
2023-04-23 21:06:21 +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
Jacob Young
ad5fb4879b std: fix memory bugs
This fixes logged errors during CI based on the new GPA checks.
2023-04-05 08:23:07 +02:00
Veikka Tuominen
5e161c102d
Merge pull request #14841 from squeek502/is-cygwin-pty-stuff
`os.isCygwinPty`: Fix a bug, replace kernel32 call, and optimize
2023-03-21 15:03:33 +02:00
Andrew Kelley
a1058dd27b fix std.fs unit test to not be racey 2023-03-15 10:48:15 -07:00
Andrew Kelley
e098b287e1 std.fs.File.writevAll: fix behavior for 0-length vectors
The OS layer expects pointer addresses to be inside the application's
address space even if the length is zero. Meanwhile, in Zig, slices may
have undefined pointer addresses when the length is zero. So this
function now modifies the iov_base fields when the length is zero.

This is a companion commit to b4893eb05565b2cb033c6ed88617d73faf878455.
2023-03-15 10:48:15 -07:00
Andrew Kelley
25c3878c00 std.fs.File.readvAll: fix behavior for 0-length vectors
The OS layer expects pointer addresses to be inside the application's
address space even if the length is zero. Meanwhile, in Zig, slices may
have undefined pointer addresses when the length is zero. So this
function now modifies the iov_base fields when the length is zero.
2023-03-15 10:48:14 -07:00
Ryan Liptak
6d74c0d1b4 Add comments explaining BUFFER_OVERFLOW during NtQueryInformationFile calls 2023-03-08 04:26:50 -08:00
Andrew Kelley
426c13dddf add doc comments to std.fs.File.default_mode 2023-03-03 01:00:44 -05: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
Luuk de Gram
772a0eb68a
Merge pull request #14661 from evacchi/zig-wasi-preopens 2023-02-19 17:09:58 +01:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Edoardo Vacchi
4940afc434 skip when builtin.link_libc 2023-02-18 22:29:11 +01: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
Andrew Kelley
ea6e0e33a7 zig build: add executable bit and file path to package hash
Unfortunately, due to the Windows equivalent of executable permissions
being a bit tricky, there is follow-up work to be done.

What is done in this commit is the hash modifications. At the fetch
layer, executable bits inside packages are ignored. In the hash
computation layer, executable bit is implemented for POSIX but not yet
for Windows. This means that the hash will not break again in the future
for packages that do not have any executable files, but it will break
for packages that do.

This is a hash-breaking change.

Closes #14308
2023-02-01 18:42:29 -07:00
pluick
2d617c482c
Fix cache-dir specified on the command line (#14076)
The resolvePosix and resolveWindows routines changed behaviour in an
earlier commit so that the return value is not always an absolute path.
That caused the relativePosix and relativeWindows to return a relative
path that is not correct.

The change in behaviour mentioned above would cause a local cache-dir to
be created in the wrong directory when --cache-dir was specified for a
build.
2023-01-05 01:37:00 -08:00
Veikka Tuominen
f83834993e std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
Sizhe Zhao
4fa027a3cc docs: Clarify that std.fs.path.resolve doesn't resolve relative path to
absolute path
2023-01-03 12:49:05 +02:00
Michael Dusan
7798af7461
dragonfly: pass test: lib/std/std.zig 2023-01-02 19:18:33 -05:00
Andrew Kelley
a62c8d36d5 std.fs.Dir.statFile rework
* revert changes to Module because the error set is consistent across
   operating systems.
 * remove duplicated Stat.fromSystem code and use a less redundant name.
 * make fs.Dir.statFile follow symlinks, and avoid pointless control
   flow through the posix layer.
2022-12-14 14:26:02 -07:00
Philippe Pittoli
f65cdef7c8 std.fs.Dir.statFile: use fstatat
This avoids extra syscalls.
2022-12-14 14:11:59 -07:00
Andrew Kelley
e73170f972 std: fix WASI regressions
This branch largely reverts 58f961f4cb9875bbce3070969438ecf08f392c9f. I
would like to revisit the proposal to modify the standard library in
this way and think more carefully about it before adding isAbsolute()
checks everywhere.
2022-12-06 12:15:05 -07:00
Andrew Kelley
9cb06f3b8b fix merge conflicts from master branch 2022-12-06 12:15:04 -07:00
Andrew Kelley
d5312d53a0 WASI: remove absolute path emulation from std lib
Instead of checking for absolute paths and current working directories
in various file system operations, there is one simple solution: allow
overriding `std.fs.cwd` on WASI.

os.realpath is back to causing a compile error when used on WASI. This
caused a compile error in the Sema handling of `@src()`. The compiler
should never call realpath, so the commit that made this change is
reverted (95ab942184427e7c9b840d71f4d093931e3e48fb). If this breaks
debug info, a different strategy is needed to solve it other than using
realpath.

I also removed the preopens code and replaced it with something much
simpler. There is no longer any global state in the standard library.

Additionally-
 * os.openat no longer does an unnecessary fstat on WASI when O.WRONLY
   is not provided.
 * os.chdir is back to causing a compile error on WASI.
2022-12-06 12:15:04 -07:00
Takeshi Yoneda
829bf5a03e wasi: fixes IterableDir.nextWasi for large directory
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-01 13:56:53 +09:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Andrew Kelley
3ae4931dc1 CLI: more careful resolution of paths
In general, we prefer compiler code to use relative paths based on open
directory handles because this is the most portable. However, sometimes
absolute paths are used, and sometimes relative paths are used that go
up a directory.

The recent improvements in 81d2135ca6ebd71b8c121a19957c8fbf7f87125b
regressed the use case when an absolute path is used for the zig lib
directory mixed with a relative path used for the root source file. This
could happen when, for example, running the standard library tests, like
this:

stage3/bin/zig test ../lib/std/std.zig

This happened because the zig lib dir was inferred to be an absolute
directory based on the zig executable directory, while the root source
file was detected as a relative path. There was no common prefix and so
it was not determined that the std.zig file was inside the lib
directory.

This commit adds a function for resolving paths that preserves relative
path names while allowing absolute paths, and converting relative
upwards paths (e.g. "../foo") to absolute paths. This restores the
previous functionality while remaining compatible with systems such as
WASI that cannot deal with absolute paths.
2022-11-28 01:23:39 -05:00
Andrew Kelley
d24aaf8847 std.fs.path.resolve: eliminate getcwd() syscall
This is a breaking change to the API. Instead of the first path
implicitly being the current working directory, it now asserts that the
number of paths passed is greater than zero.

Importantly, it never calls getcwd(); instead, it can possibly return
".", or a series of "../". This changes the error set to only be
`error{OutOfMemory}`.

closes #13613
2022-11-22 20:57:56 -07:00
Stevie Hryciw
04f3067a79 run zig fmt on everything checked by CI 2022-11-18 19:22:42 +00:00
Nick Cernis
8a5818535b
Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)
* Export invalidFmtErr

To allow consistent use of "invalid format string" compile error
response for badly formatted format strings.

See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340.

* Replace format compile errors with invalidFmtErr

- Provides more consistent compile errors.
- Gives user info about the type of the badly formated value.

* Rename invalidFmtErr as invalidFmtError

For consistency. Zig seems to use “Error” more often than “Err”.

* std: add invalid format string checks to remaining custom formatters

* pass reference-trace to comp when building build file; fix checkobjectstep
2022-11-12 21:03:24 +02:00
Veikka Tuominen
678f3f6e65
Merge pull request #13276 from r00ster91/stem
std.fs.path: add stem()
2022-11-03 16:45:37 +02:00
Ryan Liptak
db80225a97 fs: Some NAME_MAX/MAX_NAME_BYTES improvements 2022-10-29 14:30:46 -07:00
Ryan Liptak
348f73502e Make MAX_NAME_BYTES on WASI equivalent to the max of the other platforms
Make the test use the minimum length and set MAX_NAME_BYTES to the maximum so that:
- the test will work on any host platform
- *and* the MAX_NAME_BYTES will be able to hold the max file name component on any host platform
2022-10-29 14:30:46 -07:00
Ryan Liptak
c6ff1a7160 Windows: Fix iterator name buffer size not handling all possible file name components
Each u16 within a file name component can be encoded as up to 3 UTF-8 bytes, so we need to use MAX_NAME_BYTES to account for all possible UTF-8 encoded names.

Fixes #8268
2022-10-29 14:30:44 -07:00
InKryption
bc72ae5e4e Sema: Prevent coercion from tuple pointer to mutable slice.
Also fix some stdlib code affected by this.

Co-authored by: topolarity <topolarity@tapscott.me>
2022-10-27 22:00:47 -04:00
r00ster91
7721c0cbef std.fs.path: add stem() 2022-10-24 18:06:40 +02:00
r00ster91
a0a50955f0 docs(std.fs.path.extension): correct arrow alignment 2022-10-24 18:06:40 +02:00
Ryan Liptak
c8da03a0e1 Fix compile error in Dir.deleteTreeMinStackSize and add test
Follow up to #13073
2022-10-14 14:48:23 -04:00
Ryan Liptak
e9889cd25f fs: Add IterableDir.Iterator.reset 2022-10-05 03:26:13 -07:00
Evin Yulo
779c2daa19 Remove outdated comment 2022-09-28 13:00:00 +03:00
noiryuh
0be46866fe use std.ascii instead of defining ascii functions in std.fs.path 2022-09-23 12:19:09 +03:00
Evin Yulo
dab5bb9247 Fix docstring for std.fs.path.extension 2022-09-22 20:13:09 -04:00
Jakub Konka
0ae2ea671b wasm: temporarily save curr file pointer before pwriting on Win
This is a temporary workaround to an unclear platform-dependence
behavior we have in libstd for `std.fs.File` abstraction. See
https://github.com/ziglang/zig/issues/12783 for more information.
2022-09-08 14:29:54 +02:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Ryan Liptak
764cf4e53f std.fs: Fix WalkerEntry.dir not always being the containing dir
Before this commit, the modified test would fail with `FileNotFound` because the `entry.dir` would be for the entry itself rather than the containing dir of the entry. That is, if you were walking a tree of `a/b`, then (previously) the entry for `b` would incorrectly have an `entry.dir` for `b` rather than `a`.
2022-08-15 11:25:51 +03:00
Ryan Liptak
e7b6a18331 std.fs: Split Iterator.next on Linux and WASI to allow for handling platform-specific errors
Follow up to #12226, implements the compromise detailed in https://github.com/ziglang/zig/issues/12211#issuecomment-1196011590
2022-08-01 19:38:05 +03:00
Ryan Liptak
75e5b38410
std.fs: End iteration on Linux/WASI during Iterator.next when hitting ENOENT
`getdents` on Linux can return `ENOENT` if the directory referred to by the fd is deleted during iteration. Returning null when this happens makes sense because:

- `ENOENT` is specific to the Linux implementation of `getdents`
- On other platforms like FreeBSD, `getdents` returns `0` in this scenario, which is functionally equivalent to the `.NOENT => return null` handling on Linux
- In all the usage sites of `Iterator.next` throughout the standard library, translating `ENOENT` returned from `next` as null was the best way to handle it, so the use-case for handling the exact `ENOENT` scenario specifically may not exist to a relevant extent

Previously, ENOENT being returned would trigger `os.unexpectedErrno`.

Closes #12211
2022-07-25 16:14:25 +03:00
Ryan Liptak
4624c81899 std.fs: Fix Walker closing the initial directory when not fully iterated
This is a fix for a regression caused by 61c5d8f8f1

Closes #12209
2022-07-24 12:00:14 -07:00