forked from CalebQ42/squashfs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_fileinfo.go
66 lines (55 loc) · 1.16 KB
/
reader_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
59
60
61
62
63
64
65
66
package squashfs
import (
"io/fs"
"time"
"github.com/CalebQ42/squashfs/internal/directory"
"github.com/CalebQ42/squashfs/internal/inode"
)
type fileInfo struct {
e directory.Entry
size int64
perm uint32
modTime uint32
}
func (r Reader) newFileInfo(e directory.Entry) (fileInfo, error) {
i, err := r.inodeFromDir(e)
if err != nil {
return fileInfo{}, err
}
return newFileInfo(e, i), nil
}
func newFileInfo(e directory.Entry, 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{
e: e,
size: size,
perm: uint32(i.Perm),
modTime: i.ModTime,
}
}
func (f fileInfo) Name() string {
return f.e.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.e.Type == inode.Dir
}
func (f fileInfo) Sys() any {
return nil
}