aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fs/Dir.zig
AgeCommit message (Collapse)Author
2025-02-17std.Target: Remove functions that just wrap component functions.Alex Rønne Petersen
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
2025-02-10std.ArrayList: popOrNull() -> pop() [v2] (#22720)Meghan Denny
2025-02-09wasi: fix wasm-wasi-musl constantsPat Tullmann
Zig's copy of the `SYMLINK_{NO,}FOLLOW` constants from wasi-musl was wrong, as were the `IFIFO` and `IFSOCK` file type flags. Fix these up, and add comments pointing to exactly where they come from (as the wasi-musl source has lots of unused, different definitions of these constants). Add tests for the Zig convention that WASM preopen 3 is the current working directory. This is true for WASM with or without libc. Enable several fs and posix tests that are now passing (not necessarily because of this change) on wasm targets. Fixes #20890.
2025-01-16std.fs.Dir: update deleteTree doc comment to match function signature (#22509)max
the actual parameter name is `sub_path` which is also referenced in other comments describing the fuction.
2024-10-17fix compilation errors for fs and fs.Dir (#21643)Justin Braben
* fix compilation errors for fs and fs.Dir * mem.span instead of mem.sliceTo * Updating symLinkAbsoluteW function parameters * Update with expected rename semantics
2024-10-06Explain why POLL_FD_READWRITE is not dangerous at sites of useachan1989
2024-10-05Create/open file on WASI targets should have POLL_FD_READWRITE rightsachan1989
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-08-01add std.fs.Dir.HandleAndrew Kelley
mirrors std.fs.File.Handle
2024-07-29std.fs: Rework to always use statx() instead of fstat()/fstatat() on Linux.Alex Rønne Petersen
statx() is strictly superior to stat() and friends. We can do this because the standard library declares Linux 4.19 to be the minimum version supported in std.Target. This is also necessary on riscv32 where there is only statx(). While here, I improved std.fs.File.metadata() to gather as much information as possible when calling statx() since that is the expectation from this particular API.
2024-07-28Merge pull request #20297 from sno2/wtf8-conversion-buffer-overflowsAndrew Kelley
std: fix buffer overflows from improper WTF encoding
2024-07-28std.fs.Dir: Refactor atomicSymLink from std.fsCarter Snook
Deprecates std.fs.atomicSymLink and removes the allocator requirement from the new std.fs.Dir.atomicSymLink. Replaces the two usages of this within std. I did not include the TODOs from the original code that were based off of `switch (err) { ..., else => return err }` not having correct inference that cases handled in `...` are impossible in the error union return type because these are not specified in many places but I can add them back if wanted. Thank you @squeek502 for help with fixing buffer overflows!
2024-07-19fix regression of flock being called on wasi targetsAndrew Kelley
* common symbols are now public from std.c even if they live in std.posix * LOCK is now one of the common symbols since it is the same on 100% of operating systems. * flock is now void value on wasi and windows * std.fs.Dir now uses flock being void as feature detection, avoiding trying to call it on wasi and windows
2024-07-19std.c reorganizationAndrew Kelley
It is now composed of these main sections: * Declarations that are shared among all operating systems. * Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however. * Declarations that are specific to a single operating system. - These are imported one per line so you can see where they come from, protected by a comptime block to prevent accessing the wrong one. Closes #19352 by changing the convention to making types `void` and functions `{}`, so that it becomes possible to update `@hasDecl` sites to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks. A handful of types have been modified to gain namespacing and type safety. This is a breaking change. Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-09std.fs.Dir: Rename OpenDirOptions to OpenOptions (#20542)Krzysztof Wolicki
* std.fs.Dir: Rename OpenDirOptions to OpenOptions https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces * std.fs.Dir: Add deprecated alias `OpenDirOptions`
2024-07-03Rename MAX_NAME_BYTES to max_name_bytesMichael Bradshaw
2024-06-14std: fix buffer overflows from improper WTF encodingCarter Snook
Closes #20288
2024-06-13std: Convert deprecated aliases to compile errors and fix usagesRyan Liptak
Deprecated aliases that are now compile errors: - `std.fs.MAX_PATH_BYTES` (renamed to `std.fs.max_path_bytes`) - `std.mem.tokenize` (split into `tokenizeAny`, `tokenizeSequence`, `tokenizeScalar`) - `std.mem.split` (split into `splitSequence`, `splitAny`, `splitScalar`) - `std.mem.splitBackwards` (split into `splitBackwardsSequence`, `splitBackwardsAny`, `splitBackwardsScalar`) - `std.unicode` + `utf16leToUtf8Alloc`, `utf16leToUtf8AllocZ`, `utf16leToUtf8`, `fmtUtf16le` (all renamed to have capitalized `Le`) + `utf8ToUtf16LeWithNull` (renamed to `utf8ToUtf16LeAllocZ`) - `std.zig.CrossTarget` (moved to `std.Target.Query`) Deprecated `lib/std/std.zig` decls were deleted instead of made a `@compileError` because the `refAllDecls` in the test block would trigger the `@compileError`. The deleted top-level `std` namespaces are: - `std.rand` (renamed to `std.Random`) - `std.TailQueue` (renamed to `std.DoublyLinkedList`) - `std.ChildProcess` (renamed/moved to `std.process.Child`) This is not exhaustive. Deprecated aliases that I didn't touch: + `std.io.*` + `std.Build.*` + `std.builtin.Mode` + `std.zig.c_translation.CIntLiteralRadix` + anything in `src/`
2024-06-04Dir.makeOpenPathAccessMaskW: Fix leaking intermediate directory handlesRyan Liptak
Fixes a regression introduced in 67455c5e70e86dbb7805ff9a415f1b13b14f36da. The `errdefer` cannot run since its not possible for an error to occur, and we don't want it to run on the last handle, so we move the closing back down to where it was before 67455c5e70e86dbb7805ff9a415f1b13b14f36da.
2024-05-11windows: use permissive file share flags everywhere (#19505)Georgijs
* use permissive file share flags everywhere * remove file_share_delete from createnamedpipefile
2024-05-07fs: handle `OBJECT_NAME_COLLISION` in `makeOpenPath`Jacob Young
This fixes a race condition when two threads/processes try to `makeOpenPath` the same path simultaneously.
2024-05-03Rename Dir.writeFile2 -> Dir.writeFile and update all callsitesRyan Liptak
writeFile was deprecated in favor of writeFile2 in f645022d16361865e24582d28f1e62312fbc73bb. This commit renames writeFile2 to writeFile and makes writeFile2 a compile error.
2024-04-20std.fs.Dir.openDir: use wasi libc API when -lcLinus Groh
Same as #19680 but for directories.
2024-04-18std.fs.Dir.openFile: use wasi libc API when -lcAndrew Kelley
Also removes the LOCK namespace from std.c.wasi because wasi libc does not have flock. closes #19336 related to #19352 Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2024-04-14fix namespacing of std.fs.Dir.Walker.EntryAndrew Kelley
2024-04-14std.fs.Dir.Walker: maintain a null byte in path namesAndrew Kelley
2024-04-08haiku: fix directory iterationJacob Young
2024-03-19fix compilation failures found by CIAndrew Kelley
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-15bsd: debitrot std.cMichael Dusan
- follow-up to f4bf061d8a8 - updated std.fs.Dir to use properly named symbols
2024-02-29Fix symLink's handling of `/` path separators on WindowsRyan Liptak
Symlink targets require canonicalized path separators on Windows
2024-02-27Eliminate `error.InvalidHandle` from OpenError and RealPathErrorRyan Liptak
InvalidHandle in OpenError is no longer a possible error on any platform. In the past it was able to be returned in `openOptionsFromFlagsWasi`, but the implementation was changed in 7680c5330cbc9141b9a5444e30c512b6068ab50d to make it no longer possible. InvalidHandle in RealPathError was a holdover from before d5312d53a066092ba9efd687e25b29a87eb6290c, which made realpath a compile error on WASI. However, InvalidHandle was also a possible error in the FreeBSD fallback implementation added in 537624734c4db9e0cdbdc0ebce57375d17172a70. This commit changes the FreeBSD fallback implementation to return FileNotFound instead of InvalidHandle which matches how EBADF is handled in all the other `realpath` implementations (including the FreeBSD non-fallback implementation). Closes #19084
2024-02-24Fix handling of Windows (WTF-16) and WASI (UTF-8) pathsRyan Liptak
Windows paths now use WTF-16 <-> WTF-8 conversion everywhere, which is lossless. Previously, conversion of ill-formed UTF-16 paths would either fail or invoke illegal behavior. WASI paths must be valid UTF-8, and the relevant function calls have been updated to handle the possibility of failure due to paths not being encoded/encodable as valid UTF-8. Closes #18694 Closes #1774 Closes #2565
2024-02-24Update deprecated `std.unicode` function usagesRyan Liptak
2024-02-14bsd: debitrot type-safe std.c.OMichael Dusan
Minor changes as per 7680c5330cb mostly about pipe2() flags. closes #18927
2024-02-14std.os.windows.OpenFile: add missing errorAndrew Kelley
Encountered in a recent CI run on an aarch64-windows dev kit. Pretty sure I disabled the virus scanner but it looks like it turned itself back on with a Windows Update. Rather than marking the new error code as unreachable in the places where it is unexpected, this commit makes it return `error.Unexpected`.
2024-02-11some API work on std.c, std.os, std.os.wasiAndrew Kelley
* std.c: consolidate some definitions, making them share code. For example, freebsd, dragonfly, and openbsd can all share the same `pthread_mutex_t` definition. * add type safety to std.c.O - this caught a bug where mode flags were incorrectly passed as the open flags. * 3 fewer uses of usingnamespace keyword * as per convention, remove purposeless field prefixes from struct field names even if they have those prefixes in the corresponding C code. * fix incorrect wasi libc Stat definition * remove C definitions from incorrectly being in std.os.wasi * make std.os.wasi definitions type safe * go through wasi native APIs even when linking libc because the libc APIs are problematic and wasteful * don't expose WASI definitions in std.posix * remove std.os.wasi.rights_t.ALL: this is a footgun. should it be all future rights too? or only all current rights known? both are the wrong answer.
2024-02-01remove std.io.ModeVeikka Tuominen
2024-01-08fix std.fs.Dir.makePath silent failure (#16878)Amir Alawi
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-05Dir.makePath: Document/test platform differences around .. component handlingRyan Liptak
Closes #18452
2024-01-01std.fs.Dir.atomicFile: provide an option for make pathAndrew Kelley
It's useful for the API to support creating the parent directory.
2023-11-22std.fs.File: flatten structAndrew Kelley
2023-11-22std.fs: extract Dir into separate fileAndrew Kelley