diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-08-06 21:29:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 21:29:32 +0200 |
| commit | 094b893f777db2a152ba478fb9b8d54f6d91bb4f (patch) | |
| tree | f7034e19aab977ffe2b03d05d9672382368ec6a5 | |
| parent | 09de71b61c931af799b064e4c377ffecf78b6ad7 (diff) | |
| parent | e597071cbfec35f375eafb06fda6699b76478766 (diff) | |
| download | rust-094b893f777db2a152ba478fb9b8d54f6d91bb4f.tar.gz rust-094b893f777db2a152ba478fb9b8d54f6d91bb4f.zip | |
Rollup merge of #144975 - joshtriplett:file-times-dir, r=jhpratt
`File::set_times`: Update documentation and example to support setting timestamps on directories Inspired by https://github.com/rust-lang/rust/issues/123883 .
| -rw-r--r-- | library/std/src/fs.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 72ad7c244ee..b3ca118a452 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1111,6 +1111,11 @@ impl File { /// `futimes` on macOS before 10.13) and the `SetFileTime` function on Windows. Note that this /// [may change in the future][changes]. /// + /// On most platforms, including UNIX and Windows platforms, this function can also change the + /// timestamps of a directory. To get a `File` representing a directory in order to call + /// `set_times`, open the directory with `File::open` without attempting to obtain write + /// permission. + /// /// [changes]: io#platform-specific-behavior /// /// # Errors @@ -1128,7 +1133,7 @@ impl File { /// use std::fs::{self, File, FileTimes}; /// /// let src = fs::metadata("src")?; - /// let dest = File::options().write(true).open("dest")?; + /// let dest = File::open("dest")?; /// let times = FileTimes::new() /// .set_accessed(src.accessed()?) /// .set_modified(src.modified()?); |
