From 1bb14a8bb79a7dda67d678209b1b731ee1a781b9 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 5 Aug 2025 15:09:33 -0700 Subject: [PATCH 1/3] `File::set_times`: Remove `write(true)` from the example so it works on directories Inspired by https://github.com/rust-lang/rust/issues/123883 . --- library/std/src/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 72ad7c244eeba..08976ae668e8f 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1128,7 +1128,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()?); From a99860b13a7f83a74b72beeddc9802e230f60212 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 5 Aug 2025 15:10:24 -0700 Subject: [PATCH 2/3] `File::set_times`: Add documentation about setting directory timestamps Inspired by https://github.com/rust-lang/rust/issues/123883 . --- library/std/src/fs.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 08976ae668e8f..eb9f99af220da 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1111,6 +1111,10 @@ 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 do so, open the directory with `File::open`, without + /// attempting to obtain write permission. + /// /// [changes]: io#platform-specific-behavior /// /// # Errors From e597071cbfec35f375eafb06fda6699b76478766 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 6 Aug 2025 11:41:16 -0700 Subject: [PATCH 3/3] Reword documentation for `set_times` to clarify directory handling --- library/std/src/fs.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index eb9f99af220da..b3ca118a45295 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1112,8 +1112,9 @@ impl File { /// [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 do so, open the directory with `File::open`, without - /// attempting to obtain write permission. + /// 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 ///