Crate unix_mode

Source
Expand description

Manipulate Unix file mode bits.

Every filesystem entry (or inode) on Unix has a bit field of mode bits that describe both the type of the file and its permissions.

These are classically displayed in the left of ls output, and the permissions can be changed with chmod. For example:

assert_eq!(unix_mode::to_string(0o0040755), "drwxr-xr-x");
assert_eq!(unix_mode::to_string(0o0100640), "-rw-r-----");

The encoding is fairly standard across unices, and occurs in some file formats and network protocols that might be seen on non-Unix platforms, including that of rsync.

This library isn’t Unix-specific and doesn’t depend on the underlying OS to interpret the bits.

For example, this can be used with the return value from std::os::unix::fs::MetadataExt::mode.

The names of the predicate functions match std::fs::FileType and std::os::unix::fs::FileTypeExt.

§Changelog

§0.1.4

§0.1.3

  • Add Type enum for matching the file type.
  • Add Access, and Accessor enums for testing permissions.
  • More tests.
  • Move changelog into Rustdoc.

§0.1.2

§0.1.1

  • Fix tests on Windows.

§0.1.0

  • Initial release.

Enums§

Access
Enum for specifying the type of access in is_allowed
Accessor
Enum for specifying the context / “who” accesses in is_allowed
Type
The different types of files known to this library

Functions§

is_allowed
Check whether mode represents an allowed (true) or denied (false) access
is_block_device
Returns true if this mode represents a block device.
is_char_device
Returns true if this mode represents a character device.
is_dir
Returns true if this mode represents a directory.
is_fifo
Returns true if this mode represents a fifo, also known as a named pipe.
is_file
Returns true if this mode represents a regular file.
is_setgid
Returns true if the set-group-ID bit is set
is_setuid
Returns true if the set-user-ID bit is set
is_socket
Returns true if this mode represents a Unix-domain socket.
is_sticky
Returns true if the sticky bit is set
is_symlink
Returns true if this mode represents a symlink.
to_string
Convert Unix mode bits to a text string describing type and permissions, as shown in ls.