about summary refs log tree commit diff
path: root/library/std/src/fs.rs
AgeCommit message (Collapse)AuthorLines
2025-08-30Rollup merge of #144964 - 0xdeafbeef:fix-open-options, r=ibraheemdevTrevor Gross-1/+6
std: clarify `OpenOptions` error for create without write access Fixes rust-lang/rust#140621
2025-08-30std: clarify `OpenOptions` error for create without write accessVladimir Petrzhikovskii-1/+6
Previously, attempting to create/truncate a file without write/append access would result in platform-specific error messages: - Unix: "Invalid argument" - Windows: raw OS error code 87 These error codes look like system errors, which could waste hours of debugging for what is actually an API misuse issue.
2025-08-30Rollup merge of #143462 - Rudxain:read_to_string_usize, r=joboetStuart Cook-2/+2
fix(lib-std-fs): handle `usize` overflow in `read*` I assume this is a non-breaking change, as there would be an OOM `panic` anyways. This patch ensures a fast-fail when there's not enough memory to load the file. This only changes behavior on platforms where `usize` is smaller than 64bits
2025-08-27Rollup merge of #145290 - ntc2:patch-1, r=joshtriplett,tgross35Matthias Krüger-0/+3
Improve std::fs::read_dir docs Call out early that the results returned can differ across calls / aren't deterministic. This was already mentioned at the bottom of examples, but I think it's worth calling out early, since this caused at least one person (me!) great confusion.
2025-08-27Improve std::fs::read_dir docsNathan Collins-0/+3
Call out early that the results returned can differ across calls / aren't deterministic. This was already mentioned at the bottom of examples, but I think it's worth calling out early, since this caused at least one person (me!) great confusion. [ Added a comma to the docs, reflowed commit message - Trevor ]
2025-08-19Rollup merge of #142938 - lolbinarycat:std-set_permissions_nofollow, ↵许杰友 Jieyou Xu (Joe)-0/+19
r=ibraheemdev implement std::fs::set_permissions_nofollow on unix implementation of https://github.com/rust-lang/rust/issues/141607
2025-08-18implement std::fs::set_permissions_nofollow on unixbinarycat-0/+19
2025-08-16Fix typo in doc for library/std/src/fs.rs#set_permissionsAlan Urmancheev-1/+1
"privalage" -> "privilege"
2025-08-07Fix doc comment of File::try_lock and File::try_lock_sharedUlrich Stark-2/+2
2025-08-06Reword documentation for `set_times` to clarify directory handlingJosh Triplett-2/+3
2025-08-05`File::set_times`: Add documentation about setting directory timestampsJosh Triplett-0/+4
Inspired by https://github.com/rust-lang/rust/issues/123883 .
2025-08-05`File::set_times`: Remove `write(true)` from the example so it works on ↵Josh Triplett-1/+1
directories Inspired by https://github.com/rust-lang/rust/issues/123883 .
2025-07-05fix(lib-std-fs): handle `usize` overflow in `read` & `read_to_string`Ricardo Fernández Serrata-2/+2
2025-07-03Rollup merge of #134006 - klensy:typos, r=nnethercoteJana Dönszelmann-1/+1
setup typos check in CI This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying? Also includes commits with actual typo fixes. MCP: https://github.com/rust-lang/compiler-team/issues/817 typos check currently turned for: * ./compiler * ./library * ./src/bootstrap * ./src/librustdoc After merging, PRs which enables checks for other crates (tools) can be implemented too. Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr. Check typos: `python x.py test tidy --extra-checks=spellcheck` Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo) Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-07-02Rollup merge of #141847 - xizheyin:141837, r=jhprattMatthias Krüger-13/+37
Explain `TOCTOU` on the top of `std::fs`, and reference it in functions Fixes rust-lang/rust#141837 r? ``````@workingjubilee``````
2025-07-02Auto merge of #142974 - cuviper:stage0-bump, r=Mark-Simulacrumbors-10/+10
Update stage0 to 1.89.0-beta.1 - Update version placeholders - Update stage0 to 1.89.0-beta.1 - Update `STAGE0_MISSING_TARGETS` - Update `cfg(bootstrap)` r? `@Mark-Simulacrum` try-job: dist-i586-gnu-i586-i686-musl
2025-07-01Update version placeholdersJosh Stone-10/+10
2025-06-19docs(fs): Touch up grammar on lock apiEd Page-6/+6
2025-06-15Stabilize "file_lock" featureChristopher Berner-15/+10
2025-06-13Remove "intermittent" wording from `ReadDir`Chris Denton-3/+2
2025-06-05Optimize `Seek::stream_len` impl for `File`Tobias Bucher-0/+36
It uses the file metadata on Unix with a fallback for files incorrectly reported as zero-sized. It uses `GetFileSizeEx` on Windows. This reduces the number of syscalls needed for determining the file size of an open file from 3 to 1.
2025-06-02Explain TOCTOU on the top of `std::fs`, and ref it in functionsxizheyin-13/+37
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-31library: explain TOCTOU races in `fs::remove_dir_all`Jubilee Young-8/+19
In the previous description it said there was a TOCTOU race but did not explain exactly what the problem was. I sat down with the CVE, reviewed its text, and created this explanation. This context should hopefully help people understand the actual risk as-such. Incidentally, it also fixes the capitalization on the name of Redox OS.
2025-05-27Rollup merge of #141312 - cberner:filelock_from, r=joshtriplettMatthias Krüger-0/+16
Add From<TryLockError> for io::Error Adds a `From` impl to make error propagation easier, as discussed in the tracking issue `TryLockError` is unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/issues/130994 This PR also cleanups the Windows implementation of `try_lock()` and `try_lock_shared()` as [discussed here](https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485)
2025-05-25improve the `std::fs::create_dir_all` docs related to atomicityFluid-2/+2
2025-05-20Add From<TryLockError> for io::ErrorChristopher Berner-0/+16
This makes error propagation from try_lock() and try_lock_shared() more convenient
2025-05-18replace `try_reserve_exact` with `try_with_capacity` in `std::fs::read`Fluid-2/+1
2025-05-03Rollup merge of #140595 - lolbinarycat:std-set_permissions-typo, r=cuviperMatthias Krüger-1/+1
doc(std): fix typo lchown -> lchmod chown is irrelevant here, as this function does not affect file ownership. chmod is the correct function to reference here.
2025-05-03Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubileeMatthias Krüger-11/+60
Change signature of File::try_lock and File::try_lock_shared These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone These methods are unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/pull/130999 and this PR changes the signatures as discussed by libs-api: https://github.com/rust-lang/rust/issues/130994#issuecomment-2770838848
2025-05-02doc(std): fix typo lchown -> lchmodbinarycat-1/+1
2025-05-01Implement error::Error for TryLockErrorChristopher Berner-1/+4
2025-05-01Change signature of File::try_lock and File::try_lock_sharedChristopher Berner-10/+56
These methods now return Result<(), TryLockError> instead of Result<bool, Error> to make their use less errorprone
2025-05-01Rollup merge of #140062 - xizheyin:issue-139958, r=workingjubileeGuillaume Gomez-0/+2
std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently written into Closes #139958 The current documentation for `std::fs::remove_dir_all` function does not explicitly mention the error types that may be returned in concurrent scenarios. Specifically, when one thread attempts to remove a directory tree while another thread simultaneously writes files to that directory, the function may return an `io::ErrorKind::DirectoryNotEmpty` error, but this behavior is not clearly mentioned in the current documentation. r? libs
2025-04-20std: mention `remove_dir_all` can emit `DirectoryNotEmpty` when concurrently ↵xizheyin-0/+2
written into Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08clarify std::fs::set_permissions symlink behaviorbinarycat-6/+8
nest under platform-specific behavior, factor rationale into its own section, and tweak language.
2025-04-08std(docs): clarify how std::fs::set_permisions works with symlinksbinarycat-0/+13
fixes https://github.com/rust-lang/rust/issues/75942 fixes https://github.com/rust-lang/rust/issues/124201
2025-03-29Rollup merge of #138832 - ChrisDenton:with_native_path, r=joboetMatthias Krüger-8/+8
Start using `with_native_path` in `std::sys::fs` Ideally, each platform should use their own native path type internally. This will, for example, allow passing a `CStr` directly to `std::fs::File::open` and therefore avoid the need for allocating a new null-terminated C string. However, doing that for every function and platform all at once makes for a large PR that is way too prone to breaking. So this PR does some minimal refactoring which should help progress towards that goal. The changes are Unix-only and even then I avoided functions that require more changes so that this PR is just moving things around. r? joboet
2025-03-29Start using with_native_path in std::sys::fsChris Denton-8/+8
2025-03-22Rollup merge of #138822 - moxian:unlock, r=joshtriplettMatthias Krüger-5/+10
De-Stabilize `file_lock` This reverts #136794 FCP on the tracking issue (#130994) passsed successfully https://github.com/rust-lang/rust/issues/130994#issuecomment-2646158607 but there are now concerns about the suitability of the proposed API (https://github.com/rust-lang/rust/issues/130994#issuecomment-2734608366) On zullip it was [suggested](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/File.3A.3Atry_lock.20API.3A.20Result.3Cbool.3E/near/506823067) that it would be better to temporarily(?) destabilize the feature ASAP to buy us some more time reflecting on the API. This PR implements the revert. The feature is not currently on beta (https://github.com/rust-lang/rust/blob/beta/library/std/src/fs.rs#L672) so a beta backport is not yet neccessary. If this revert is accepted, the tracking issue (#130994) should be reopened
2025-03-21Revert "Stabilize file_lock"moxian-5/+10
This reverts commit 82af73dd4c58cd6bec5fb44cf02f7ac96b1ed48b.
2025-03-14Forward `stream_position` in `Arc<File>` as wellTobias Bucher-0/+3
It was missed in #137165.
2025-03-10Disable unsupported testsNicole LeGare-1/+2
Unclear why this needs to be done manually and is not done by the existing Trusty patches.
2025-03-07Return OutOfMemoryError and update docsChris Denton-1/+1
2025-03-05Rollup merge of #137240 - jieyouxu:remove_dir_all, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-3/+5
Slightly reformat `std::fs::remove_dir_all` error docs To make the error cases easier to spot on a quick glance, as I've been bitten by this a couple of times already 💀 cc #137230.
2025-02-19Rollup merge of #136794 - cberner:stabilize, r=joshtriplettMatthias Krüger-10/+5
Stabilize file_lock Closes #130994
2025-02-19Rollup merge of #136347 - allevo:patch-1, r=AmanieuMatthias Krüger-0/+1
Add a bullet point to `std::fs::copy` I needed to copy a file but I got the following error: ``` Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` After read the documentation, I though the error was generated by the `from` parameter, forgetting the `to` part. Anyway, I got the error because the parent folder of `to` didn't exist. Even if the documentation explicitly saying `but is not limited to just these cases`, I would like to add this case because I spent 3 hours around it. This PR just wants to put a mention about it.
2025-02-19Update library/std/src/fs.rsTommaso Allevi-1/+1
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-19std::fs: slightly reformat `remove_dir_all` error docs许杰友 Jieyou Xu (Joe)-3/+5
To make the error cases easier to spot on a quick glance.
2025-02-18Rollup merge of #136876 - joshtriplett:locking-might-not-be-advisory, r=AmanieuMatthias Krüger-38/+58
Locking documentation updates - Reword file lock documentation to clarify advisory vs mandatory. Remove the word "advisory", and make it more explicit that the lock may be advisory or mandatory depending on platform. - Document that locking a file fails on Windows if the file is opened only for append