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]: e9b6085088/library/std/src/sys/fs/unix.rs (L1395-L1410)
This commit is contained in:
Weihang Lo 2025-09-09 00:05:40 -04:00
parent 9eb32405e9
commit 8f51d7f68b
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -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,
}
}