-
Notifications
You must be signed in to change notification settings - Fork 6
/
permissions.go
49 lines (45 loc) · 1.29 KB
/
permissions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package vfs
// Permissions of a file. Unlike regular UNIX file system, no
// distinction is made between owner, group and all permissions. This is
// because the virtual file system is effectively single user.
type Permissions uint8
const (
// PermissionsRead indicates that file contents may be read, or
// that files in a directory may be listed.
PermissionsRead Permissions = 1 << iota
// PermissionsWrite indicates that file contents may be written
// to, or that files in a directory may be added, removed or
// renamed.
PermissionsWrite
// PermissionsExecute indicates that a file is executable, or
// that files in a directory may be looked up.
PermissionsExecute
)
// NewPermissionsFromMode creates a set of permissions from a
// traditional UNIX style mode.
func NewPermissionsFromMode(m uint32) (p Permissions) {
if m&0o444 != 0 {
p |= PermissionsRead
}
if m&0o222 != 0 {
p |= PermissionsWrite
}
if m&0o111 != 0 {
p |= PermissionsExecute
}
return
}
// ToMode converts a set of permissions to a traditional UNIX style
// mode. The permissions for the owner, group and all will be identical.
func (p Permissions) ToMode() (m uint32) {
if p&PermissionsRead != 0 {
m |= 0o444
}
if p&PermissionsWrite != 0 {
m |= 0o200
}
if p&PermissionsExecute != 0 {
m |= 0o111
}
return
}