fmodeparser
This crate is a library for parsing file permission in Unix-like system .
It provides a way to parse and manipulate file permissions in a Unix-like system.
It is useful for working with file permissions in Rust programs.
It is designed to be easy to use and provides a simple API for working with file permissions.
It provides a trait extension for the std::fs::Metadata type that allows you to directly call
a single method to the file permission from the metadata.
Permission formats and file kinds representation
the file permission its octal mode consists of 6-digit number the first three digits are for the file kind:
| digits | shortcut usage | file kind |
|--------|----------------|------------------|
| 100 | - | regular file |
| 120 | l | symlink |
| 020 | c | character device |
| 060 | b | block device |
| 010 | p | fifo |
| 140 | s | socket |
| 040 | d | directory |
(read, write, execute, -) (r,w,x, -).
| digits | permission |
|---|---|
| 0 | --- |
| 1 | --x |
| 2 | -w- |
| 3 | -wx |
| 4 | r-- |
| 5 | r-x |
| 6 | rw- |
| 7 | rwx |
if we have a file with permission 33188 decimal = 100644 octal = -rw-r--r--
such that :
- - : file type
- rw- : user permission
- r-- : group permission
- r-- : other permission
Examples
Import the ModeParseS trait which uses FullPermission struct under the hood
for which its method will be used as an extension for the fs::Metadata type.
It's the safest way to use this API!
Extension on Metadata type
In most times you will use it like this:
use Metadata;
use Path;
use FullPermissionError;
use PermStrParser;
Using FullPermission struct
Or you can use the FullPermission struct for manipulating the permission before asserting it
to a file :
use Path;
use FullPermission;
use FullPermissionError;
use MetadataExt;
use Error;
Using FullPermissionBuilder struct
You can also use the FullPermissionBuilder struct to build the permission
This will return a FullPermission object !
use FullPermissionBuilder;
use FullPermissionError;
use Error;