Commit Graph

48 Commits

Author SHA1 Message Date
Vadim Petrochenkov 0d70e588e6 library: Fix a symlink test failing on Windows 2024-01-06 01:40:56 +03:00
bors 77d1699756 Auto merge of #116438 - ChrisDenton:truncate, r=thomcc
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-13 02:27:12 +00:00
bors 9cf18e98f8 Auto merge of #117248 - ChrisDenton:ci-symlink, r=m-ou-se
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-12-01 19:34:40 +00:00
Sebastian Thiel a8ece1190b Add support for pre-unix-epoch file dates on Apple platforms (#108277)
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-31 17:00:59 +01:00
Chris Denton 8ade047454 Error if symlinks not supported in CI 2023-10-26 21:08:11 +01:00
Chris Denton 46f68ccb8b Skip test if Unix sockets are unsupported 2023-10-20 18:10:34 +01:00
Chris Denton c6f7aa0eea Make File::create work on Windows hidden files
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-15 10:51:20 +01:00
Chris Denton 2f5dea0978 Test that unix sockets exist on Windows 2023-10-13 06:02:38 +01:00
bors a6236fa460 Auto merge of #102757 - pcc:android-std-tests, r=workingjubilee
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-07-26 07:57:32 +00:00
Thom Chiovoloni 37854aab76 Update tvOS support elsewhere in the stdlib 2023-06-21 14:59:40 -07:00
beetrees 246dcbcbcd Add test for FileTimes 2023-05-15 15:04:45 +01:00
Chris Denton 6e377849c0 Correctly convert an NT path to a Win32 path
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-05-03 10:24:56 +01:00
Tomasz Miąsko defa245624 Implement read_buf for a few more types
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-06 12:24:15 +01:00
Peter Collingbourne fed6fceb6f 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 with an #[ignore] directive.
2023-03-02 16:08:51 -08:00
Chris Denton f7a132f428 Move rename_directory from ui-fulldeps to std
std has had a `TempDir` implementation for a long time now.
2023-02-21 18:33:19 +00:00
Ayush Singh c50d3e28ab Replace libc::{type} with crate::ffi::{type}
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-28 11:24:13 +05:30
Thom Chiovoloni a4bf36e87b Update rand in the stdlib tests, and remove the getrandom feature from it 2023-01-04 14:52:41 -08:00
Tavian Barnes 9fb7c5ae5e fs/tests: Fail fast on duplicate errors rather than looping indefinitely 2022-12-14 10:03:46 -05:00
Tavian Barnes 1550a2506d fs/tests: Explicitly kill the zombie rather than sleeping until it dies 2022-12-14 10:03:42 -05:00
Tavian Barnes ba4dd464f5 fs: Fix #50619 (again) and add a regression test
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-12-12 17:17:26 -05:00
Arthur Carcano 6259028862 Add test for regression for FileType equality
Cf: https://github.com/rust-lang/rust/issues/104900
2022-11-30 23:45:01 +01:00
Chris Denton eee8ca9a44 Ignore hiberfil_sys test in CI
The file it's testing does not exist in the CI environment.
2022-07-18 15:06:07 +01:00
Chris Denton 5f5bcb3697 Test if [try_]exists can find hiberfil.sys 2022-07-05 12:24:01 +01:00
Chris Denton 2d0650457f Add comment and simplify hiberfil_sys test 2022-07-05 12:05:51 +01:00
Chris Denton 8d4adad953 Windows: Use FindFirstFileW if metadata fails
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-07-05 09:15:35 +01:00
James 'zofrex' Sanderson ef59ab738e Use gender neutral terms 2022-04-07 08:51:59 +01:00
Dan Gohman 6c407d0592 Add a testcase. 2022-03-20 15:56:25 -07:00
Dylan DPC 7189fceab7 Rollup merge of #93283 - m1guelperez:master, r=Mark-Simulacrum
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-11 13:38:36 +01:00
T-O-R-U-S 72a25d05bf Use implicit capture syntax in format_args
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).
2022-03-10 10:23:40 -05:00
Miguel Perez b795ae5280 Fix for issue #93283 2022-03-08 10:16:18 +01:00
Tavian Barnes d0c8b29ec6 fs: Add a regression test for #93384 2022-01-29 16:37:21 -05:00
Hans Kratz 54e22eb7db Fix CVE-2022-21658 for UNIX-like 2022-01-19 15:59:22 +01:00
Lucas Kent b656384d83 Update stdlib to the 2021 edition 2021-12-18 00:21:53 +11:00
Frank Steffahn a957cefda6 Fix a bunch of typos 2021-12-14 16:40:43 +01:00
Yuki Okushi f62984fca9 Rollup merge of #90942 - JohnTitor:should-os-error-3, r=m-ou-se
windows: Return the "Not Found" error when a path is empty

Fixes #90940
2021-11-19 13:06:35 +09:00
Yuki Okushi ddc1d58ca8 windows: Return the "Not Found" error when a path is empty 2021-11-17 03:11:14 +09:00
tamaron 181716a16c compare between Path instead of str 2021-11-11 11:40:34 +09:00
Chris Denton f1efc7efb2 Make sure CreateDirectoryW works for path lengths > 247 2021-10-23 19:35:24 +01:00
Ali Malik e43254aad1 Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
Aris Merchant 5999a5fbdc Make tests pass on old macos
On old macos systems, `fs::hard_link()` will follow symlinks.
This changes the test `symlink_hard_link` to exit early on
these systems, so that tests can pass.
2021-07-10 12:59:25 -07:00
Mara Bos a0d11a4fab Rename ErrorKind::Unknown to Uncategorized. 2021-06-15 14:30:13 +02:00
Mara Bos 0b37bb2bc2 Redefine ErrorKind::Other and stop using it in std. 2021-06-15 14:22:49 +02:00
Christiaan Dirkx 0895a693bd Fix test metadata_access_times to also check for Unsupported 2021-04-18 09:29:24 +02:00
Vadim Petrochenkov a5bc780b50 std: Fix test got_symlink_permission on Windows 2020-11-16 21:09:26 +03:00
Dylan DPC 41134be153 Rollup merge of #78026 - sunfishcode:symlink-hard-link, r=dtolnay
Define `fs::hard_link` to not follow symlinks.

POSIX leaves it [implementation-defined] whether `link` follows symlinks.
In practice, for example, on Linux it does not and on FreeBSD it does.
So, switch to `linkat`, so that we can pick a behavior rather than
depending on OS defaults.

Pick the option to not follow symlinks. This is somewhat arbitrary, but
seems the less surprising choice because hard linking is a very
low-level feature which requires the source and destination to be on
the same mounted filesystem, and following a symbolic link could end
up in a different mounted filesystem.

[implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
2020-11-09 01:13:28 +01:00
Dan Gohman 91a9f83dd1 Define fs::hard_link to not follow symlinks.
POSIX leaves it implementation-defined whether `link` follows symlinks.
In practice, for example, on Linux it does not and on FreeBSD it does.
So, switch to `linkat`, so that we can pick a behavior rather than
depending on OS defaults.

Pick the option to not follow symlinks. This is somewhat arbitrary, but
seems the less surprising choice because hard linking is a very
low-level feature which requires the source and destination to be on
the same mounted filesystem, and following a symbolic link could end
up in a different mounted filesystem.
2020-10-16 12:05:49 -07:00
wcampbell a93f58f5e6 Join map operators
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 17:01:09 -04:00
Lzu Tao a4e926daee std: move "mod tests/benches" to separate files
Also doing fmt inplace as requested.
2020-08-31 02:56:59 +00:00