Giter Site home page Giter Site logo

stevelauc / unixpermissionsext Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18 KB

A trivial trait bringing missing functions that are not exposed by PermissionsExt to Permissions on UNIX platforms.

License: GNU General Public License v2.0

Rust 100.00%
file-permissions set-uid unix sticky-bit set-gid

unixpermissionsext's Introduction

UNIXPermissionsExt

BUILD crates.io docs.rs

A trivial trait bringing missing functions that are not exposed by std::os::unix::fs::PermissionsExt to std::fs::Permissions on UNIX platforms.

pub trait UNIXPermissionsExt {
    fn set_uid(&self) -> bool;
    fn set_gid(&self) -> bool;
    fn sticky_bit(&self) -> bool;
    fn readable_by_owner(&self) -> bool;
    fn writable_by_owner(&self) -> bool;
    fn executable_by_owner(&self) -> bool;
    fn readable_by_group(&self) -> bool;
    fn writable_by_group(&self) -> bool;
    fn executable_by_group(&self) -> bool;
    fn readable_by_other(&self) -> bool;
    fn writable_by_other(&self) -> bool;
    fn executable_by_other(&self) -> bool;
    fn stringify(&self) -> String;
}

impl UNIXPermissionsExt for Permissions {
    ...
}

Usage

  1. Add it to your dependency:

    $ cd $YOUR_PROJECT
    $ cargo add unix_permissions_ext
  2. Import this trait and use it just like you are using the standard library!

    use std::fs::metadata;
    use unix_permissions_ext::UNIXPermissionsExt;
    
    let metadata = metadata("/usr/bin/passwd").expect("can not fetch metadata");
    let permission = metadata.permissions();
    
    assert!(permission.set_uid());
    println!("Permission: {}", permission.stringify());
  3. To use these functions directly with the mode_t type, consider importing raw_fn module:

    use unix_permissions_ext::raw_fn::*;

Contributing

Contributions of all forms are welcome, feel free to file an issue or make a pull request!

Test before your commit

  1. Pass the tests

    $ cargo test
  2. Format your code

    $ cargo fmt

unixpermissionsext's People

Contributors

stevelauc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.