about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-08-27 21:51:53 -0400
committerGitHub <noreply@github.com>2025-08-27 21:51:53 -0400
commitad42340e391f3625dbf5899da2901d398346fd72 (patch)
tree92c85c6bee32de827da6c885644b9824e3b1227d /library/std
parenta1c543e165a5fd7bd769a07707bb770aadb07786 (diff)
parent6e5a4275f7dca9ba13b4234b3fe821816753d924 (diff)
Rollup merge of #145746 - ivmarkov:fix-nofollow-espidf, r=ibraheemdev
Fix STD build failing for target_os = "espidf"

A regression from rust-lang/rust#142938

cc `@lolbinarycat`
cc `@ibraheemdev`

ESP-IDF (and a few other embedded Tier-3 systems) is considered `cfg(unix)`, but it does not have the `O_NOFOLLOW` flag because neither of its three supported filesystems (FATFS, LitteLF and Spiffs) has symbolic links in the first place.

What this fix does is to keep the `set_permissions_nofollow` method available and non-failing for ESP-IDF, but it behaves as if no `O_NONFOLLOW` was set. This should be fine as there is nothing to follow in the first place, as there are no symbolic links there.

EDIT: Also added the same fix for Horizon, as requested by `@Meziu.`
Diffstat (limited to 'library/std')
-rw-r--r--library/std/src/sys/fs/mod.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/library/std/src/sys/fs/mod.rs b/library/std/src/sys/fs/mod.rs
index dbd782f5018..0276bf6e64c 100644
--- a/library/std/src/sys/fs/mod.rs
+++ b/library/std/src/sys/fs/mod.rs
@@ -117,9 +117,18 @@ pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
 #[cfg(unix)]
 pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io::Result<()> {
     use crate::fs::OpenOptions;
-    use crate::os::unix::fs::OpenOptionsExt;
 
-    OpenOptions::new().custom_flags(libc::O_NOFOLLOW).open(path)?.set_permissions(perm)
+    let mut options = OpenOptions::new();
+
+    // ESP-IDF and Horizon do not support O_NOFOLLOW, so we skip setting it.
+    // Their filesystems do not have symbolic links, so no special handling is required.
+    #[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
+    {
+        use crate::os::unix::fs::OpenOptionsExt;
+        options.custom_flags(libc::O_NOFOLLOW);
+    }
+
+    options.open(path)?.set_permissions(perm)
 }
 
 #[cfg(not(unix))]