forked from sevennt/rocketmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperm.go
52 lines (44 loc) · 1000 Bytes
/
perm.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
50
51
52
package rocketmq
import (
"bytes"
)
type permName struct {
PermPriority int
PermRead int
PermWrite int
PermInherit int
}
var PermName = permName{
PermPriority: 0x1 << 3,
PermRead: 0x1 << 2,
PermWrite: 0x1 << 1,
PermInherit: 0x1 << 0,
}
func (p permName) perm2String(perm int) string {
stringBuffer := bytes.NewBuffer([]byte{})
if PermName.isReadable(perm) {
stringBuffer.WriteString("R")
} else {
stringBuffer.WriteString("-")
}
if PermName.isWritable(perm) {
stringBuffer.WriteString("W")
} else {
stringBuffer.WriteString("-")
}
if PermName.isInherited(perm) {
stringBuffer.WriteString("X")
} else {
stringBuffer.WriteString("-")
}
return stringBuffer.String()
}
func (p permName) isReadable(perm int) bool {
return (perm & p.PermRead) == p.PermRead
}
func (p permName) isWritable(perm int) bool {
return (perm & p.PermWrite) == p.PermWrite
}
func (p permName) isInherited(perm int) bool {
return (perm & p.PermInherit) == p.PermInherit
}