is_executable

Crates.iois_executable
lib.rsis_executable
version1.0.4
sourcesrc
created_at2017-09-20 22:02:34.92332
updated_at2024-10-04 19:16:11.72013
descriptionIs there an executable file at the given path?
homepage
repositoryhttps://github.com/fitzgen/is_executable
max_upload_size
id32461
size23,344
Nick Fitzgerald (fitzgen)

documentation

https://docs.rs/is_executable

README

is_executable

Is there an executable file at the given path?

CI

A small helper function which determines whether or not the given path points to an executable file. If there is no file at the given path, or the file is not executable, then false is returned. When there is a file and the file is executable, then true is returned.

This crate works on both Unix-based operating systems (macOS, Linux, FreeBSD, etc...) and Windows.

Does not help with time-of-check to time-of use (TOCTOU) races.

The API comes in two flavors:

  1. An extension trait to add an is_executable method on std::path::Path:

    use std::path::Path;
    use is_executable::IsExecutable;
    
    fn main() {
        let path = Path::new("some/path/to/a/file");
    
        // Determine if `path` is executable.
        if path.is_executable() {
            println!("The path is executable!");
        } else {
            println!("The path is _not_ executable!");
        }
    }
    
  2. For convenience, a standalone is_executable function, which takes any AsRef<Path>:

    use std::path::Path;
    
    use is_executable::is_executable;
    
    fn main() {
        let path = Path::new("some/path/to/a/file");
    
        // Determine if `path` is executable.
        if is_executable(&path) {
            println!("The path is executable!");
        } else {
            println!("The path is _not_ executable!");
        }
    }
    

License: Apache-2.0/MIT

Commit count: 28

cargo fmt