2020-01-19 06:41:05 +00:00
|
|
|
package vfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-01-31 18:04:00 +00:00
|
|
|
// FileInfo implements os.FileInfo for a file in S3.
|
|
|
|
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.
|
|
|
|
func NewFileInfo(name string, isDirectory bool, sizeInBytes int64, modTime time.Time) FileInfo {
|
2020-01-19 06:41:05 +00:00
|
|
|
mode := os.FileMode(0644)
|
|
|
|
if isDirectory {
|
|
|
|
mode = os.FileMode(0755) | os.ModeDir
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:04:00 +00:00
|
|
|
return FileInfo{
|
2020-01-19 06:41:05 +00:00
|
|
|
name: name,
|
|
|
|
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()
|
|
|
|
}
|