Check if a file is executable
(path: &Path)
| 21 | |
| 22 | /// Check if a file is executable |
| 23 | pub fn is_executable(path: &Path) -> bool { |
| 24 | #[cfg(unix)] |
| 25 | { |
| 26 | use std::os::unix::fs::PermissionsExt; |
| 27 | if let Ok(metadata) = fs::metadata(path) { |
| 28 | let permissions = metadata.permissions(); |
| 29 | return permissions.mode() & 0o111 != 0; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | #[cfg(not(unix))] |
| 34 | { |
| 35 | // On Windows, check common executable extensions |
| 36 | if let Some(ext) = path.extension() { |
| 37 | let ext = ext.to_string_lossy().to_lowercase(); |
| 38 | return matches!(ext.as_str(), "exe" | "bat" | "cmd" | "sh" | "py" | "ps1"); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | false |
| 43 | } |
| 44 | |
| 45 | /// Get total size of a directory recursively |
| 46 | pub fn get_dir_size(path: &Path) -> u64 { |
no outgoing calls
no test coverage detected