Permissions

From Xojo Documentation

Class (inherits from Object)


Enables you to test, set, and clear the permissions of FolderItems in operating systems that support this concept (macOS and Linux). You can get and set the permissions of a FolderItem as an octal Integer via the Permissions property of the FolderItem class.

Properties
GIDBit OthersExecute OwnerRead
GroupExecute OthersRead OwnerWrite
GroupRead OthersWrite StickyBit
GroupWrite OwnerExecute UIDBit
Constructors

Constructor(FolderItem.Permissions as Integer)


Notes

On Unix-based operating systems, permissions can be represented as a three-digit numeric code, in which each digit ranges from 0 to 7 (a.k.a, an octal number). The digits correspond to the permissions of the FolderItem Owner, the owning Group, and Other users not in the owning Group, in that order, from left to right.

The code for each digit is computed using the following values:

Value Permission Type Description
4 Read permissions User or group can open and read the FolderItem.
2 Write permissions User or group can open and write to the FolderItem.
1 Execute permissions User or group can execute the file or read the directory.

For directories, Execute permissions means that the user or group can list the contents of the directory and examine the files that the user has permission to read.

For each digit, the permissions are expressed by adding up the values. Each digit can take on eight possible values:

Value Description
0 No permissions
1 Execute permissions
2 Write permissions
3 Write and Execute permissions
4 Read permissions
5 Read and Execute permissions
6 Read and Write permissions
7 Read, Write, and Execute permissions

For example, the code "764" is interpreted as follows:

Value User Type Description
7 Owner Read, Write, and Execute permissions
6 Group Read and Write permissions
4 Others Read permissions

Sample Code

The following example sets the permissions for a file. It is for Unix-based operating systems only. Twelve checkboxes on the layout enable the user to set or deselect each type of permission. When the file is opened, these checkboxes are set by reading the current permissions of the file. This code is in a PushButton that sets the permissions for the file.

// The user wants to set the permissions based
// on the checkbox states

// Make a new, cleared permissions object
Var p As New Permissions(0)

//And set the permissions by reading the CheckBoxes
p.StickyBit = CheckBox1.Value
p.UidBit = CheckBox2.Value
p.GidBit = CheckBox3.Value
p.OwnerExecute = CheckBox4.Value
p.OwnerWrite = CheckBox5.Value
p.OwnerRead = CheckBox6.Value
p.GroupExecute = CheckBox7.Value
p.GroupWrite = CheckBox8.Value
p.GroupRead = CheckBox9.Value
p.OthersExecute = CheckBox10.Value
p.OthersWrite = CheckBox11.Value
p.OthersRead = CheckBox12.Value

// Set the file's permissions
// mFile is the file that was opened with GetOpenFolderItem
mFile.Permissions = p

// And display the octal value
TextField1.Value = Oct(mFile.Permissions)

// Display the owner and group as well
TextField2.Value = mFile.Group
TextField3.Value = mFile.Owner

See Also

FolderItem class.