about summary refs log tree commit diff
path: root/library/std/src/fs.rs
AgeCommit message (Collapse)AuthorLines
2023-02-15Suggest simpler fs helper methods in File::{open,create}Kornel-1/+10
2023-02-15Demonstrate I/O in File examplesKornel-0/+9
2023-01-14Fix some missed double spaces.André Vennberg-1/+1
2023-01-11use with_capacity in read read_to_stringyukang-4/+2
2023-01-08Remove unnecessary lseek syscall when using std::fs::readyukang-2/+6
2022-12-03Rollup merge of #105100 - jhpratt:fix-docs, r=JohnTitorYuki Okushi-2/+3
Add missing intra-doc link Trivial change. This makes the plain text into inline code and makes it a link. `@rustbot` label +A-docs
2022-12-01Add tracking issue for file_create_newAndrius Pukšta-1/+1
2022-11-30Add missing intra-doc linkJacob Pratt-2/+3
2022-09-19Document surprising and dangerous fs::Permissions behaviour on UnixTim Hutt-3/+64
This documents the very surprising behaviour that `set_readonly(false)` will make a file *world writable* on Unix. I would go so far as to say that this function should be deprecated on Unix, or maybe even entirely. But documenting the bad behaviour is a good first step.
2022-09-03updated description of File struct in std::fsBart Massey-1/+1
2022-08-29Rollup merge of #98801 - joshtriplett:file-create-new, r=thomccDylan DPC-0/+29
Add a `File::create_new` constructor We have `File::create` for creating a file or opening an existing file, but the secure way to guarantee creating a new file requires a longhand invocation via `OpenOptions`. Add `File::create_new` to handle this case, to make it easier for people to do secure file creation.
2022-08-18Address reviewer commentsNick Cameron-2/+2
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05non-linux platformsNick Cameron-3/+3
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04std::io: migrate ReadBuf to BorrowBuf/BorrowCursorNick Cameron-5/+5
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-01Auto merge of #98246 - joshtriplett:times, r=m-ou-sebors-0/+81
Support setting file accessed/modified timestamps Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-15Add alias `File::set_modified` as shorthandJosh Triplett-0/+9
2022-07-15Support setting file accessed/modified timestampsJosh Triplett-0/+72
Add `struct FileTimes` to contain the relevant file timestamps, since most platforms require setting all of them at once. (This also allows for future platform-specific extensions such as setting creation time.) Add `File::set_file_time` to set the timestamps for a `File`. Implement the `sys` backends for UNIX, macOS (which needs to fall back to `futimes` before macOS 10.13 because it lacks `futimens`), Windows, and WASI.
2022-07-12Add a `File::create_new` constructorJosh Triplett-0/+29
We have `File::create` for creating a file or opening an existing file, but the secure way to guarantee creating a new file requires a longhand invocation via `OpenOptions`. Add `File::create_new` to handle this case, to make it easier for people to do secure file creation.
2022-07-11Add std::fs::write documentation precisionLucas Dumont-0/+6
As mentioned in #97947, the documentation is updated
2022-06-14Stabilize `Path::try_exists()` and improve docMartin Habovstiak-2/+6
This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-01Fix Windows file metadata docsReilly Wood-2/+2
Retrieving file metadata on Windows now uses GetFileInformationByHandle not GetFileAttributesEx
2022-05-09Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errorsbors-3/+3
Remove `#[rustc_deprecated]` This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`. I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-04-30add aliases for std::fs::canonicalizejulio-0/+2
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-3/+3
2022-04-11Document that DirEntry holds the directory openMartin Pool-0/+10
2022-04-05Document synchronicityChris Denton-0/+6
2022-03-29Warn that platform-specific behavior may changeMartin Pool-1/+1
2022-03-24Document Linux kernel handoff in std::io::copy and std::fs::copyMartin Pool-2/+8
2022-03-20Rollup merge of #94749 - RalfJung:remove-dir-all-miri, r=cuviperMatthias Krüger-3/+4
remove_dir_all: use fallback implementation on Miri Fixes https://github.com/rust-lang/miri/issues/1966 The new implementation requires `openat`, `unlinkat`, and `fdopendir`. These cannot easily be shimmed in Miri since libstd does not expose APIs corresponding to them. So for now it is probably easiest to just use the fallback code in Miri. Nobody should run Miri as root anyway...
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-3/+3
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-08docsRalf Jung-3/+4
2022-02-08Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisaMatthias Krüger-1/+1
Use `NtCreateFile` instead of `NtOpenFile` to open a file Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`. NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-2/+2
2022-02-01Link `try_exists` docs to `Path::exists`Chris Denton-1/+3
2022-01-24Use `NtCreateFile` instead of `NtOpenFile` to open a fileChris Denton-1/+1
2022-01-20Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbiniMatthias Krüger-4/+8
Fix CVE-2022-21658 See https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html. Patches reviewed by `@m-ou-se.` r? `@ghost`
2022-01-19Update std::fs::remove_dir_all documentationPietro Albini-4/+8
2022-01-14Typos fixMaxwase-1/+1
2022-01-10Improve documentation for File::options to give a more likely exampleJosh Triplett-4/+5
`File::options().read(true).open(...)` is equivalent to just `File::open`. Change the example to set the `append` flag instead, and then change the filename to something more likely to be written in append mode.
2021-12-11Correct since attribute for featureMaxwase-1/+1
2021-12-09Auto merge of #81156 - DrMeepster:read_buf, r=joshtriplettbors-13/+9
Implement most of RFC 2930, providing the ReadBuf abstraction This replaces the `Initializer` abstraction for permitting reading into uninitialized buffers, closing #42788. This leaves several APIs described in the RFC out of scope for the initial implementation: * read_buf_vectored * `ReadBufs` Closes #42788, by removing the relevant APIs.
2021-11-09Stabilize File::options()Jubilee Young-5/+4
Renames File::with_options to File::options, per consensus in rust-lang/rust#65439, and stabilizes it.
2021-11-02add read_buf for &FileDrMeepster-0/+4
2021-11-02more efficent File::read_buf impl for windows and unixDrMeepster-1/+5
2021-11-02read_bufDrMeepster-13/+1
2021-10-31Rollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplettMatthias Krüger-0/+6
Add #[must_use] to remaining std functions (A-N) I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from A-N. I added these functions myself. Clippy predictably ignored the `mut` ones, but I don't know why the rest weren't flagged. Check them closely, please? Maybe I overlooked good reasons. ```rust std::backtrace::Backtrace const fn disabled() -> Backtrace; std::backtrace::Backtrace<'a> fn frames(&'a self) -> &'a [BacktraceFrame]; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn key_mut(&mut self) -> &mut K; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_mut(&mut self) -> &mut V; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value(&mut self) -> (&K, &V); std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value_mut(&mut self) -> (&mut K, &mut V); std::env fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString>; std::env fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_>; std::io::Error fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)>; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplettMatthias Krüger-0/+1
Add #[must_use] to len and is_empty Parent issue: #89692 r? `@joshtriplett`
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+6
2021-10-30Add #[must_use] to len and is_emptyJohn Kugelman-0/+1
2021-10-13Merge branch 'master' into is-symlink-stabilizationMax Wase-15/+45