about summary refs log tree commit diff
path: root/library/std/src/fs.rs
AgeCommit message (Collapse)AuthorLines
2025-02-18Reorder "This lock may be advisory or mandatory." earlier in the lock docsJosh Triplett-18/+18
2025-02-18Clarify that locking on Windows also works for files opened with `.read(true)`Josh Triplett-5/+5
2025-02-17Use tell for <File as Seek>::stream_positionThalia Archibald-0/+6
2025-02-11Document that locking a file fails on Windows if the file is opened only for ↵Josh Triplett-0/+15
append
2025-02-11Reword file lock documentation to clarify advisory vs mandatoryJosh Triplett-35/+40
Remove the word "advisory", and make it more explicit that the lock may be advisory or mandatory depending on platform.
2025-02-11Rollup merge of #136704 - benschulz:patch-1, r=ibraheemdevJacob Pratt-2/+2
Improve examples for file locking The `lock` and `try_lock` documentation states that "if the file not open for writing, it is unspecified whether this function returns an error." With this change, the examples use `File::create` instead of `File::open`, eliminating the possibility of someone blindly copying code with unspecified behavior.
2025-02-09Stabilize file_lockChristopher Berner-10/+5
2025-02-09Rollup merge of #134679 - ChrisDenton:rm-readonly, r=Mark-SimulacrumUrgau-2/+2
Windows: remove readonly files When calling `remove_file`, we shouldn't fail to delete readonly files. As the test makes clear, this make the Windows behaviour consistent with other platforms. This also makes us internally consistent with `remove_dir_all`. try-job: x86_64-msvc-ext1
2025-02-07Improve examples for file lockingBen Schulz-2/+2
2025-01-31Update fs.rsTommaso Allevi-0/+1
2025-01-30Improve documentation for file lockingJosh Triplett-17/+40
Add notes to each method stating that locks get dropped on close. Clarify the return values of the try methods: they're only defined if the lock is held via a *different* file handle/descriptor. That goes along with the documentation that calling them while holding a lock via the *same* file handle/descriptor may deadlock. Document the behavior of unlock if no lock is held.
2025-01-26Update platform information for remove_fileChris Denton-2/+2
2025-01-24Add `File already exists` error doc to `hard_link` functionHarshit Verma-0/+1
If the link path already exists, the error `AlreadyExists` is returned. This commit adds this error to the docs.
2024-12-22docs: Permissions.readonly() also ignores root user special permissionsMarti Raudsepp-6/+11
The root user can write to files without any (write) access bits set. But this is not taken into account by `std::fs::Permissions.readonly()`.
2024-12-21Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, ↵Matthias Krüger-3/+5
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-26std: update internal uses of `io::const_error!`joboet-1/+1
2024-11-21Mention that std::fs::remove_dir_all fails on filesPanagiotis "Ivory" Vasilopoulos-1/+2
This is explicitly mentioned for std::fs::remove_file's documentation, but not in the aforementioned function. It is more likely for a slightly lazy programmer to believe that removing a file would work and that they do not have to distinguish between directories (with contents) and files themself, because of the function's recursive nature and how it distinguishes between files and directories when removing them.
2024-11-18Mention std::fs::remove_dir_all in std::fs::remove_dirPanagiotis "Ivory" Vasilopoulos-0/+4
2024-11-11Rollup merge of #130999 - cberner:flock_pr, r=joboetMatthias Krüger-0/+217
Implement file_lock feature This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag This is the initial implementation of https://github.com/rust-lang/rust/issues/130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
2024-10-28clarified std::fs truncate docyakiimoninja-1/+1
Co-authored-by: nora <48135649+Noratrieb@users.noreply.github.com>
2024-10-28clarified doc for `std::fs::OpenOptions.truncate()`yakiimoninja-1/+1
Clarified what method does when `truncate` parameter is set to `true`.
2024-10-20fix docsklensy-1/+1
2024-10-13Implement file_lock featureChristopher Berner-0/+217
This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag
2024-10-09Mention allocation errors for `open_buffered`Josh Stone-1/+2
2024-09-30Win: Use `FILE_RENAME_FLAG_POSIX_SEMANTICS` for `std::fs::rename` if availableGeorge Tokmaji-3/+5
Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming. If it isn't supported, we fall back to `FileRenameInfo`. This commit also replicates `MoveFileExW`'s behavior of checking whether the source file is a mount point and moving the mount point instead of resolving the target path.
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-1/+9
2024-09-24Add a tracking issue for `file_buffered`Josh Stone-2/+2
2024-09-24Pre-allocate buffers in `File::open_buffered` and `create_buffered`Josh Stone-2/+8
2024-09-24Add `File::open_buffered` and `create_buffered`Josh Stone-0/+71
2024-09-21Rollup merge of #129718 - lolbinarycat:remove_dir-docs, r=NoratriebMatthias Krüger-0/+10
add guarantee about remove_dir and remove_file error kinds approved in ACP https://github.com/rust-lang/libs-team/issues/433
2024-09-20Remove double spacesnora-2/+2
2024-09-20Rollup merge of #128209 - beetrees:no-macos-10.10, r=jieyouxuGuillaume Gomez-7/+6
Remove macOS 10.10 dynamic linker bug workaround Rust's current minimum macOS version is 10.12, so the hack can be removed. This PR also updates the `remove_dir_all` docs to reflect that all supported macOS versions are protected against TOCTOU race conditions (the fallback implementation was already removed in #127683). try-job: dist-x86_64-apple try-job: dist-aarch64-apple try-job: dist-apple-various try-job: aarch64-apple try-job: x86_64-apple-1
2024-09-19[Clippy] Swap `open_options` to use diagnostic items instead of pathsGnomedDev-0/+2
2024-09-18Clarify docs for std::fs::File::writeAlexey Shekhirin-1/+1
2024-09-04Remove macOS 10.10 dynamic linker bug workaroundbeetrees-7/+6
2024-08-28add guarantee about remove_dir and remove_file error kindsbinarycat-0/+10
approved in ACP https://github.com/rust-lang/libs-team/issues/433
2024-08-22fix: fs::remove_dir_all: treat ENOENT as successbinarycat-0/+2
fixes #127576 windows implementation still needs some work
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-1/+1
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-28Update CURRENT_RUSTC_VERSIONMark Rousskov-1/+1
2024-07-26Fix doc nitsJohn Arundel-10/+10
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-24Improved clarity of documentation for std::fs::create_dir_allrik86189-7/+2
2024-06-22Rollup merge of #126140 - eduardosm:stabilize-fs_try_exists, r=AmanieuMatthias Krüger-8/+5
Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_exists FCP completed in tracking issue. Tracking issue: https://github.com/rust-lang/rust/issues/83186 Closes https://github.com/rust-lang/rust/issues/83186 Stabilized API: ```rust mod fs { pub fn exists<P: AsRef<Path>>(path: P) -> io::Result<bool>; } ```
2024-06-16Rollup merge of #125112 - tbu-:pr_create_dir_all_empty, r=dtolnayJacob Pratt-0/+3
Document behavior of `create_dir_all` wrt. empty path The behavior makes sense because `Path::new("one_component").parent() == Some(Path::new(""))`, so if one naively wants to create the parent directory for a file to be written, it simply works. Closes #105108 by documenting the current behavior.
2024-06-14Polish `std::path::absolute` documentation.Kevin Reid-1/+1
These changes bring it closer to other standard library documentation and, in particular, `std::fs::canonicalize`, which it will often be compared with. * Add `# Platform-specific behavior` section, with content moved from Examples section. * Create `# Errors` section. * Phrase error description to allow future platforms to have new syntactic errors, rather than only emptiness. * Add missing commas. * Indent example code 4 spaces.
2024-06-11Rename `std::fs::try_exists` to `std::fs::exists` and stabilize fs_try_existsEduardo Sánchez Muñoz-8/+5
2024-05-21Document behavior of `create_dir_all` wrt. empty pathTobias Bucher-0/+3
The behavior makes sense because `Path::new("one_component").parent() == Some(Path::new(""))`, so if one naively wants to create the parent directory for a file to be written, it simply works. Closes #105108 by documenting the current behavior.
2024-05-20Document platform-specifics for `Read` and `Write` of `File`Tobias Bucher-0/+76
2024-05-08Rollup merge of #124782 - anatawa12:docs-create-new-already-exists, ↵Jubilee-0/+9
r=workingjubilee add note about `AlreadyExists` to `create_new` Fixes #119244
2024-05-06Apply suggestions from code reviewanatawa12-2/+6
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-05-06add note about `AlreadyExists` to `create_new`anatawa12-0/+5