-
Notifications
You must be signed in to change notification settings - Fork 5
/
defines_fileinfo.go
executable file
·57 lines (44 loc) · 1.12 KB
/
defines_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
package gsftp
import (
"os"
"time"
"cloud.google.com/go/storage"
)
type SyntheticFileInfo struct {
objAttr *storage.ObjectAttrs
prefix string
}
func (f *SyntheticFileInfo) Name() string { // base name of the file
if f.objAttr.Prefix != "" {
return f.objAttr.Prefix[len(f.prefix) : len(f.objAttr.Prefix)-1]
}
return f.objAttr.Name[len(f.prefix):]
}
func (f *SyntheticFileInfo) Size() int64 { // length in bytes for regular files; system-dependent for others
return f.objAttr.Size
}
func (f *SyntheticFileInfo) Mode() os.FileMode { // file mode bits
if f.IsDir() {
return os.ModeDir | 0777
}
return 0777
}
func (f *SyntheticFileInfo) ModTime() time.Time { // modification time
if f.IsDir() {
return time.Now()
}
return f.objAttr.Updated
}
func (f *SyntheticFileInfo) IsDir() bool { // abbreviation for Mode().IsDir()
if f.objAttr.Prefix != "" {
return true
} else if len(f.objAttr.Name) > 0 {
if f.objAttr.Name[len(f.objAttr.Name)-1:] == "/" && f.objAttr.Size == 0 {
return true
}
}
return false
}
func (f *SyntheticFileInfo) Sys() interface{} { // underlying data source (can return nil)
return nil
}