2020-01-19 06:41:05 +00:00
|
|
|
package vfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-08-11 21:56:10 +00:00
|
|
|
"path"
|
2020-01-19 06:41:05 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-08-11 21:56:10 +00:00
|
|
|
// FileInfo implements os.FileInfo for a Cloud Storage file.
|
2020-01-31 18:04:00 +00:00
|
|
|
type FileInfo struct {
|
2020-01-19 06:41:05 +00:00
|
|
|
name string
|
|
|
|
sizeInBytes int64
|
|
|
|
modTime time.Time
|
|
|
|
mode os.FileMode
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:04:00 +00:00
|
|
|
// NewFileInfo creates file info.
|
2020-08-22 12:52:17 +00:00
|
|
|
func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time.Time, fullName bool) FileInfo {
|
2020-01-19 06:41:05 +00:00
|
|
|
mode := os.FileMode(0644)
|
|
|
|
if isDirectory {
|
|
|
|
mode = os.FileMode(0755) | os.ModeDir
|
|
|
|
}
|
2020-08-22 12:52:17 +00:00
|
|
|
if !fullName {
|
|
|
|
// we have always Unix style paths here
|
|
|
|
name = path.Base(name)
|
|
|
|
}
|
2020-01-19 06:41:05 +00:00
|
|
|
|
2020-01-31 18:04:00 +00:00
|
|
|
return FileInfo{
|
2020-08-22 12:52:17 +00:00
|
|
|
name: name,
|
2020-01-19 06:41:05 +00:00
|
|
|
sizeInBytes: sizeInBytes,
|
|
|
|
modTime: modTime,
|
|
|
|
mode: mode,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name provides the base name of the file.
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) Name() string {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size provides the length in bytes for a file.
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) Size() int64 {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.sizeInBytes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode provides the file mode bits
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) Mode() os.FileMode {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.mode
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModTime provides the last modification time.
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) ModTime() time.Time {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.modTime
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDir provides the abbreviation for Mode().IsDir()
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) IsDir() bool {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.mode&os.ModeDir != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sys provides the underlying data source (can return nil)
|
2020-01-31 18:04:00 +00:00
|
|
|
func (fi FileInfo) Sys() interface{} {
|
2020-01-19 06:41:05 +00:00
|
|
|
return fi.getFileInfoSys()
|
|
|
|
}
|