-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileinfo.go
53 lines (44 loc) · 936 Bytes
/
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
package main
import (
"os"
"time"
"cloud.google.com/go/storage"
)
type SyntheticFileInfo struct {
objAttr *storage.ObjectAttrs
prefix string
}
func (f *SyntheticFileInfo) Name() string {
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 {
return f.objAttr.Size
}
func (f *SyntheticFileInfo) Mode() os.FileMode {
if f.IsDir() {
return os.ModeDir | 0777
}
return 0777
}
func (f *SyntheticFileInfo) ModTime() time.Time {
if f.IsDir() {
return time.Now()
}
return f.objAttr.Updated
}
func (f *SyntheticFileInfo) IsDir() bool {
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{} {
return nil
}