From 8f51d7f68b0998f42846899c691e25ebb355a8ae Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 9 Sep 2025 00:05:40 -0400 Subject: [PATCH] fix(flock): check if they are marked unsupported in libstd Before this Cargo invokes syscalls and check whether it gets ENOTSUP to determine flock is unsupported. However, now the "unsupported platforms" are pre-defined by libstd [1]. Cargo should perhaps return unsupported if a platform is marked unsupported by libstd. Without this, some people on Termux may be affected I guess? [1]: https://github.com/rust-lang/rust/blob/e9b6085088fd671ecfbe4cbebe1d26796d8bfa30/library/std/src/sys/fs/unix.rs#L1395-L1410 --- src/cargo/util/flock.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index a818a0b15a1..9c929de995a 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -435,13 +435,15 @@ fn error_unsupported(err: &std::io::Error) -> bool { #[allow(unreachable_patterns)] Some(libc::ENOTSUP | libc::EOPNOTSUPP) => true, Some(libc::ENOSYS) => true, - _ => false, + _ => err.kind() == std::io::ErrorKind::Unsupported, } } #[cfg(windows)] fn error_unsupported(err: &std::io::Error) -> bool { use windows_sys::Win32::Foundation::ERROR_INVALID_FUNCTION; - err.raw_os_error() - .map_or(false, |x| x == ERROR_INVALID_FUNCTION as i32) + match err.raw_os_error() { + Some(code) if code == ERROR_INVALID_FUNCTION as i32 => true, + _ => err.kind() == std::io::ErrorKind::Unsupported, + } }