Skip to content

Commit ad42340

Browse files
authored
Rollup merge of #145746 - ivmarkov:fix-nofollow-espidf, r=ibraheemdev
Fix STD build failing for target_os = "espidf" A regression from #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.`
2 parents a1c543e + 6e5a427 commit ad42340

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

library/std/src/sys/fs/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,18 @@ pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
117117
#[cfg(unix)]
118118
pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io::Result<()> {
119119
use crate::fs::OpenOptions;
120-
use crate::os::unix::fs::OpenOptionsExt;
121120

122-
OpenOptions::new().custom_flags(libc::O_NOFOLLOW).open(path)?.set_permissions(perm)
121+
let mut options = OpenOptions::new();
122+
123+
// ESP-IDF and Horizon do not support O_NOFOLLOW, so we skip setting it.
124+
// Their filesystems do not have symbolic links, so no special handling is required.
125+
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
126+
{
127+
use crate::os::unix::fs::OpenOptionsExt;
128+
options.custom_flags(libc::O_NOFOLLOW);
129+
}
130+
131+
options.open(path)?.set_permissions(perm)
123132
}
124133

125134
#[cfg(not(unix))]

0 commit comments

Comments
 (0)