-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
file_info.go
68 lines (57 loc) · 1.22 KB
/
file_info.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
62
63
64
65
66
67
68
package squashfs
import (
"io/fs"
"time"
"github.com/CalebQ42/squashfs/low/directory"
"github.com/CalebQ42/squashfs/low/inode"
)
type fileInfo struct {
name string
size int64
perm uint32
modTime uint32
fileType uint16
}
func (r Reader) newFileInfo(e directory.Entry) (fileInfo, error) {
i, err := r.Low.InodeFromEntry(e)
if err != nil {
return fileInfo{}, err
}
return newFileInfo(e.Name, &i), nil
}
func newFileInfo(name string, i *inode.Inode) fileInfo {
var size int64
if i.Type == inode.Fil {
size = int64(i.Data.(inode.File).Size)
} else if i.Type == inode.EFil {
size = int64(i.Data.(inode.EFile).Size)
}
return fileInfo{
name: name,
size: size,
perm: uint32(i.Perm),
modTime: i.ModTime,
fileType: i.Type,
}
}
func (f fileInfo) Name() string {
return f.name
}
func (f fileInfo) Size() int64 {
return f.size
}
func (f fileInfo) Mode() fs.FileMode {
if f.IsDir() {
return fs.FileMode(f.perm | uint32(fs.ModeDir))
}
return fs.FileMode(f.perm)
}
func (f fileInfo) ModTime() time.Time {
return time.Unix(int64(f.modTime), 0)
}
func (f fileInfo) IsDir() bool {
return f.fileType == inode.Dir || f.fileType == inode.EDir
}
func (f fileInfo) Sys() any {
return nil
}