fix(ocr): main builds on Windows again: the executable check is its own function per platform (#7222)

Since Rust 1.100, clippy's needless_bool refused program_is_executable on Windows: with the
#[cfg(unix)] block gone it read if ... { return false; } true, and the Windows gate failed on
every main commit since 13 Nov 09:38. The check is now one expression with the platform part
in has_execute_permission; behaviour is unchanged on every platform.
This commit is contained in:
FredApps authored and GitHub committed 2026-11-13 16:28:29 +01:00
1 parent fd4d60ff4a
commit ec31c55763
1 file changed
+16 -12
+16 -12
View File
@@ -130,18 +130,22 @@ pub fn program_is_usable(program: &Path) -> bool {
/// executable FILE (on Unix the executable bits must be set; elsewhere being a file is what
/// the OS requires). A directory or a missing file is simply unavailable — never a panic.
fn program_is_executable(program: &Path) -> bool {
if !program.is_absolute() || !program.is_file() {
return false;
}
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::metadata(program).is_ok_and(|m| m.permissions().mode() & 0o111 != 0)
}
#[cfg(not(unix))]
{
true
}
program.is_absolute() && program.is_file() && has_execute_permission(program)
}
/// Unix: an executable bit is set.
#[cfg(unix)]
fn has_execute_permission(program: &Path) -> bool {
use std::os::unix::fs::PermissionsExt;
std::fs::metadata(program).is_ok_and(|m| m.permissions().mode() & 0o111 != 0)
}
/// Elsewhere, being a file is what the OS requires. A function of its own: inlined above, the
/// Windows build reduced to `if … { return false; } true`, which clippy's `needless_bool`
/// refuses (Rust 1.100).
#[cfg(not(unix))]
fn has_execute_permission(_program: &Path) -> bool {
true
}
/// One row of Tesseract's TSV output. `level` 5 rows are the words; `conf` is −1 on the header