-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.go
61 lines (54 loc) · 1.03 KB
/
type.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
53
54
55
56
57
58
59
60
61
package squashfs
import "io/fs"
type Type uint16
const (
DirType Type = iota + 1
FileType
SymlinkType
BlockDevType
CharDevType
FifoType
SocketType
XDirType
XFileType
XSymlinkType
XBlockDevType
XCharDevType
XFifoType
XSocketType
)
// Basic returns the type as a basic type (ie. XDirType.Basic() == DirType)
func (t Type) Basic() Type {
if t >= 8 {
return t - 7
}
return t
}
func (t Type) IsDir() bool {
return t.Basic() == DirType
}
func (t Type) IsSymlink() bool {
return t.Basic() == SymlinkType
}
// Mode returns a fs.FileMode for this type that contains no permissions, only the file's type
func (t Type) Mode() fs.FileMode {
switch t.Basic() {
case DirType:
return fs.ModeDir
case FileType:
return 0
case SymlinkType:
return fs.ModeSymlink
case BlockDevType:
return fs.ModeDevice // block device
case CharDevType:
return fs.ModeDevice | fs.ModeCharDevice // char device
case FifoType:
return fs.ModeNamedPipe
case SocketType:
return fs.ModeSocket
default:
// ??
return fs.ModeIrregular
}
}