Skip to content

Mode

Unix st_mode bits: permissions, the set-user-ID/set-group-ID/sticky bits, and the file type.

Example

Reading a file's mode and applying it elsewhere:

let Metadata(info) = fs.metadata "template.sh"
let mode = info.mode
update_metadata "script.sh" mode: $mode
let rw = Mode(:OWNER_READ:, :OWNER_WRITE:)

Inherits from: Iterable[ModeBit]

Constructor

Mode ...flags -> Mode overload 1 of 2

Constructs a flag set from symbols.

Parameters

NameTypeDescription
...flags ModeBit

Mode flags -> Mode overload 2 of 2

Constructs a flag set from one iterable of symbols.

Parameters

NameTypeDescription
flags Iterable[ModeBit]

Class Methods

from_int value -> Mode

Constructs a mode from a raw st_mode value, preserving unknown bits.

Parameters

NameTypeDescription
value Int Raw mode bits.

Example

let mode = Mode.from_int 0o644

Fields

group @ security.unix.Permission [get]

Group permissions.

int @ Int [get]

The raw st_mode value, including the file type bits.

Mask with 0o7777 for the permission bits alone.

let Metadata(info) = fs.metadata "script.sh"
let mode = info.mode
assert_eq (mode.int & 0o7777) 0o755
other @ security.unix.Permission [get]

Permissions for everyone else.

owner @ security.unix.Permission [get]

Owner permissions.

Methods

(band)[S @ Mode] other -> S

Returns the flags set in both.

Parameters

NameTypeDescription
self S Receiver.
other S

(bnot)[S @ Mode]() -> S

Returns the flags of the type that are not set.

Parameters

NameTypeDescription
self S Receiver.

(bor)[S @ Mode] other -> S

Returns the flags set in either.

Parameters

NameTypeDescription
self S Receiver.
other S

(bxor)[S @ Mode] other -> S

Returns the flags set in exactly one.

Parameters

NameTypeDescription
self S Receiver.
other S

contains flag -> Bool

Tests whether all flags named by flag are set.

Parameters

NameTypeDescription
flag ModeBit