about summary refs log tree commit diff
path: root/library/std/src/fs
AgeCommit message (Collapse)AuthorLines
2024-12-27Fix renaming symlinks on WindowsChris Denton-0/+29
Previously we only detected mount points and not other types of links when determining reparse point behaviour.
2024-12-21Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, ↵Matthias Krüger-0/+41
r=ChrisDenton Win: Use POSIX rename semantics for `std::fs::rename` if available Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming and renaming if the target file is has already been opened with `FILE_SHARE_DELETE`, in which case the file gets renamed on disk while the open file handle still refers to the old file, just like in POSIX. This resolves #123985, where atomic renaming proved difficult to impossible due to race conditions. If `FileRenameInfoEx` isn't available due to missing support from the underlying filesystem or missing OS support, the renaming is retried with `FileRenameInfo`, which matches the behavior of `MoveFileEx`. This PR also manually replicates parts of `MoveFileEx`'s internal logic, as reverse-engineered from the disassembly: If the source file is a reparse point and said reparse point is a mount point, the mount point itself gets renamed; otherwise the reparse point is resolved and the result renamed. Notes: - Currently, the `win7` target doesn't bother with `FileRenameInfoEx` at all; it's probably desirable to remove that special casing and try `FileRenameInfoEx` anyway if it doesn't exist, in case the binary is run on newer OS versions. Fixes #123985
2024-11-13Fix compilation error on Solaris due to flock usageChristopher Berner-0/+28
PR 130999 added the file_lock feature, but libc does not define flock() for the Solaris platform leading to a compilation error. Additionally, I went through all the Tier 2 platforms and read through their documentation to see whether flock was implemented. This turned up 5 more Unix platforms where flock is not supported, even though it may exist in the libc crate.
2024-10-19Support lock() and lock_shared() on async IO FilesChristopher Berner-0/+38
2024-10-13Implement file_lock featureChristopher Berner-0/+80
This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag
2024-09-30Win: Add test cases for renaming a directory while the target file is opened ↵George Tokmaji-0/+41
and for renaming over a non-empty directory
2024-09-25Use `&raw` in the standard libraryJosh Stone-1/+1
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-07Remove now redundant check in symlink_hard_link testMads Marquart-18/+0
We support macOS 10.12 and above, so it now always uses linkat, so the check is redundant. This was missed in #126351.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-14/+12
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-19Avoid ref when using format! for perfYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a tiny perf cost. A few more minor related cleanups.
2024-07-14Auto merge of #125935 - madsmtm:merge-os-apple, r=workingjubileebors-20/+3
Merge Apple `std::os` extensions modules into `std::os::darwin` The functionality available on Apple platforms are very similar, and were (basically) duplicated for each platform. This PR rectifies that by merging the code into one module. Ultimately, I've done this to fix `./x build library --target=aarch64-apple-tvos,aarch64-apple-watchos,aarch64-apple-visionos`, as that currently fails because of dead code warnings. Publically exposing these to tvOS/watchOS/visionOS targets is considered in https://github.com/rust-lang/rust/pull/123723, but that seems to be dragging out, and in any case I think it makes sense to do the refactor separately from stabilization. r? libs Fixes https://github.com/rust-lang/rust/issues/121640 and https://github.com/rust-lang/rust/issues/124825.
2024-07-14Merge Apple `std::os` extensions modules into `std::os::darwin`Mads Marquart-20/+3
The functionality available on Apple platforms are very similar, and were duplicated for each platform. Additionally, this fixes a warning when compiling the standard library for tvOS, watchOS and visionOS by marking the corresponding code as dead code.
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-1/+1
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > if it’s stabilized soon enough maybe it’s not worth having a > standard library method that will be replaceable with > `let buffer = [MaybeUninit::<T>::uninit(); $N];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-05-28Make more of the test suite run on Mac CatalystMads Marquart-1/+1
This adds the `only-apple`/`ignore-apple` compiletest directive, and uses that basically everywhere instead of `only-macos`/`ignore-macos`. Some of the updates in `run-make` are a bit redundant, as they use `ignore-cross-compile` and won't run on iOS - but using Apple in these is still more correct, so I've made that change anyhow.
2024-04-28Use `target_vendor = "apple"` instead of `target_os = "..."`Mads Marquart-31/+4
2024-04-14Rollup merge of #120900 - marcospb19:std-use-seek-stream-position, ↵Guillaume Gomez-24/+24
r=joshtriplett std: use `stream_position` where applicable by replacing `seek(SeekFrom::Current(0))` calls
2024-03-18Support for visionOSAdam Gastineau-3/+14
2024-03-12Convert [u8] to [i8] in testChris Denton-0/+1
2024-02-27Implement junction_pointChris Denton-7/+5
2024-02-11std: use `stream_position` where applicableJoão Marcos P. Bezerra-24/+24
by replacing `seek(SeekFrom::Current(0))` calls
2024-01-06library: Fix a symlink test failing on WindowsVadim Petrochenkov-2/+4
2023-12-13Auto merge of #116438 - ChrisDenton:truncate, r=thomccbors-1/+26
Windows: Allow `File::create` to work on hidden files This makes `OpenOptions::new().write(true).create(true).truncate(true).open(&path)` work if the path exists and is a hidden file. Previously it would fail with access denied. This makes it consistent with `OpenOptions::new().write(true).truncate(true).open(&path)` (note the lack of `create`) which does not have this restriction. It's also more consistent with other platforms. Fixes #115745 (see that issue for more details).
2023-12-01Auto merge of #117248 - ChrisDenton:ci-symlink, r=m-ou-sebors-1/+1
Error if symlinks are not supported in CI In CI we want to run as many tests as possible and be alerted if a test isn't run for any reason.
2023-10-31Add support for pre-unix-epoch file dates on Apple platforms (#108277)Sebastian Thiel-0/+42
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec struct used in various system calls represents this as a number of seconds and a number of nanoseconds. Nanoseconds are required to be between 0 and 999_999_999, because the portion outside that range should be represented in the seconds field; if nanoseconds were larger than 999_999_999, the seconds field should go up instead. Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems that support times before the epoch, that's seconds=-86400, one day before the epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other words, a tenth of a second after one minute before the epoch. On most UNIX systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS bug is that it returns seconds=-59, nanoseconds=-900_000_000. While that's in some sense an accurate description of the time (59.9 seconds before the epoch), that violates the invariant of the timespec data structure: nanoseconds must be between 0 and 999999999. This causes this assertion in the Rust standard library. So, on macOS, if we get a Timespec value with seconds less than or equal to zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add 1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then convert. The resulting timespec value is still accepted by macOS, and when fed back into the OS, produces the same results. (If you set a file's mtime with that timestamp, then read it back, you get back the one with negative nanoseconds again.) Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-26Error if symlinks not supported in CIChris Denton-1/+1
2023-10-20Skip test if Unix sockets are unsupportedChris Denton-2/+11
2023-10-15Make File::create work on Windows hidden filesChris Denton-1/+26
Previously it failed on Windows if the file had the `FILE_ATTRIBUTE_HIDDEN` attribute set. This was inconsistent with `OpenOptions::new().write(true).truncate(true)` which can truncate an existing hidden file.
2023-10-13Test that unix sockets exist on WindowsChris Denton-0/+35
2023-07-26Auto merge of #102757 - pcc:android-std-tests, r=workingjubileebors-0/+2
Make std tests pass on newer Android Newer versions of Android forbid the creation of hardlinks as well as Unix domain sockets in the /data filesystem via SELinux rules, which causes several tests depending on this behavior to fail. So let's skip these tests on Android if we see an EACCES from one of these syscalls. To achieve this, introduce a macro with the horrible name of or_panic_or_skip_on_android_eacces (better suggestions welcome) which skips (returns from) the test if an EACCES return value is seen on Android.
2023-06-21Update tvOS support elsewhere in the stdlibThom Chiovoloni-3/+25
2023-05-15Add test for `FileTimes`beetrees-2/+52
2023-05-03Correctly convert an NT path to a Win32 pathChris Denton-1/+5
This can be done by simply changing the `\??\` prefix to `\\?\` and then attempting to convert to a user path. Currently it simply strips off the prefix which could lead to the wrong path being returned (e.g. if it's not a drive path or if the path contains trailing spaces, etc).
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-1/+19
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-02Make std tests pass on newer AndroidPeter Collingbourne-0/+2
Newer versions of Android forbid the creation of hardlinks as well as Unix domain sockets in the /data filesystem via SELinux rules, which causes several tests depending on this behavior to fail. So let's skip these tests on Android with an #[ignore] directive.
2023-02-21Move `rename_directory` from ui-fulldeps to stdChris Denton-0/+16
std has had a `TempDir` implementation for a long time now.
2023-01-28Replace libc::{type} with crate::ffi::{type}Ayush Singh-2/+2
Replace libc::{type} imports with crate::ffi::{type} outside of `std::sys` and `std::os`. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-01-04Update rand in the stdlib tests, and remove the getrandom feature from itThom Chiovoloni-3/+3
2022-12-14fs/tests: Fail fast on duplicate errors rather than looping indefinitelyTavian Barnes-2/+2
2022-12-14fs/tests: Explicitly kill the zombie rather than sleeping until it diesTavian Barnes-7/+9
2022-12-12fs: Fix #50619 (again) and add a regression testTavian Barnes-0/+26
Bug #50619 was fixed by adding an end_of_stream flag in #50630. Unfortunately, that fix only applied to the readdir_r() path. When I switched Linux to use readdir() in #92778, I inadvertently reintroduced the bug on that platform. Other platforms that had always used readdir() were presumably never fixed. This patch enables end_of_stream for all platforms, and adds a Linux-specific regression test that should hopefully prevent the bug from being reintroduced again.
2022-11-30Add test for regression for FileType equalityArthur Carcano-0/+16
Cf: https://github.com/rust-lang/rust/issues/104900
2022-07-18Ignore `hiberfil_sys` test in CIChris Denton-1/+4
The file it's testing does not exist in the CI environment.
2022-07-05Test if `[try_]exists` can find `hiberfil.sys`Chris Denton-2/+4
2022-07-05Add comment and simplify `hiberfil_sys` testChris Denton-5/+6
2022-07-05Windows: Use `FindFirstFileW` if `metadata` failsChris Denton-0/+11
Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.
2022-04-07Use gender neutral termsJames 'zofrex' Sanderson-3/+3
2022-03-20Add a testcase.Dan Gohman-0/+6
2022-03-11Rollup merge of #93283 - m1guelperez:master, r=Mark-SimulacrumDylan DPC-1/+9
Fix for localized windows editions in testcase fn read_link() Issue#93211 This PR aims to fix the issue with localized windows versions that do not necessarily have the folder "Documents and settings" in English. The idea was provided by `@the8472.` We check if the "CI" environment variable is set, then we always check for the "Documents and Settings"-folder, otherwise we check if the folder exists on the local machine, and if not we skip this assert. Resoles #93211.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-5/+5
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).