-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefixfs_file_info.go
54 lines (48 loc) · 1.13 KB
/
prefixfs_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
package backupfs
import (
"io/fs"
"strings"
"time"
)
// filePath and prefix are expected to be normalized (filepath.Clean) paths
func newPrefixFileInfo(base fs.FileInfo, filePath, prefix string) fs.FileInfo {
var (
nameOverride = ""
baseName = base.Name()
)
if filePath == prefix {
nameOverride = separator
} else if prefix != "" && strings.HasPrefix(baseName, prefix) {
nameOverride = strings.TrimPrefix(baseName, prefix)
}
return &prefixFileInfo{
baseFi: base,
nameOverride: nameOverride,
}
}
// A FileInfo describes a file and is returned by Stat.
type prefixFileInfo struct {
baseFi fs.FileInfo
nameOverride string
}
func (fi *prefixFileInfo) Name() string {
if fi.nameOverride != "" {
return fi.nameOverride
}
return fi.baseFi.Name()
}
func (fi *prefixFileInfo) Size() int64 {
return fi.baseFi.Size()
}
func (fi *prefixFileInfo) Mode() fs.FileMode {
return fi.baseFi.Mode()
}
func (fi *prefixFileInfo) ModTime() time.Time {
return fi.baseFi.ModTime()
}
func (fi *prefixFileInfo) IsDir() bool {
return fi.baseFi.IsDir()
}
func (fi *prefixFileInfo) Sys() interface{} {
return fi.baseFi.Sys()
}