Module permissions
Provides utilities for working with file permissions.
Functions
strtobmp (permstr) | Convert a string representation to a binary one. |
bmptostr (bitmap) | Convert a bitmap representation to a string. |
has_permission (mode, perm) | Check if a permission is set. |
Functions
- strtobmp (permstr)
-
Convert a string representation to a binary one.
Takes a string in a form similar to that output by
ls
, and returns a number with the appropriate bits set. The string must be exactly nine characters long and in the formatrwxrwxrwx
, where anyr
,w
, orx
may be replaced by a-
. For example,rwxrw-r--
,r-xr-xr-x
, andrw--wx--w-
are all valid, butrwrwrw
is not.Parameters:
- permstr string The string to process
Returns:
-
number
A numerical representation of the input string
- bmptostr (bitmap)
-
Convert a bitmap representation to a string.
The bitmap must be in the same format as a POSIX file mode - the same as that returned by strtobmp.
Parameters:
- bitmap number The permissions to process
Returns:
- has_permission (mode, perm)
-
Check if a permission is set.
Checks if the given permission string, when ANDed with the given
mode
, is exactly returned. Relatively inflexible.Parameters:
- mode number The file mode to check against
- perm string The permissions to check
Returns:
-
boolean
Whether the given permission is set