-
Notifications
You must be signed in to change notification settings - Fork 12
/
fileinfo.go
58 lines (53 loc) · 1.15 KB
/
fileinfo.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
package cpio
import (
"os"
"path"
"time"
)
// fileInfo implements fs.FileInfo.
type fileInfo struct {
h *Header
}
// Name returns the base name of the file.
func (fi fileInfo) Name() string {
if fi.IsDir() {
return path.Base(path.Clean(fi.h.Name))
}
return path.Base(fi.h.Name)
}
func (fi fileInfo) Size() int64 { return fi.h.Size }
func (fi fileInfo) IsDir() bool { return fi.Mode().IsDir() }
func (fi fileInfo) ModTime() time.Time { return fi.h.ModTime }
func (fi fileInfo) Sys() interface{} { return fi.h }
func (fi fileInfo) Mode() (mode os.FileMode) {
mode = os.FileMode(fi.h.Mode).Perm()
if fi.h.Mode&ModeSetuid != 0 {
mode |= os.ModeSetuid
}
if fi.h.Mode&ModeSetgid != 0 {
mode |= os.ModeSetgid
}
if fi.h.Mode&ModeSticky != 0 {
mode |= os.ModeSticky
}
m := os.FileMode(fi.h.Mode) & ModeType
if m == ModeDir {
mode |= os.ModeDir
}
if m == ModeNamedPipe {
mode |= os.ModeNamedPipe
}
if m == ModeSymlink {
mode |= os.ModeSymlink
}
if m == ModeDevice {
mode |= os.ModeDevice
}
if m == ModeCharDevice {
mode |= os.ModeDevice | os.ModeCharDevice
}
if m == ModeSocket {
mode |= os.ModeSocket
}
return mode
}