github.com/viant/toolbox@v0.34.5/storage/file_info.go (about) 1 package storage 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 "time" 8 ) 9 10 type fileInfo struct { 11 name string 12 size int64 13 mode os.FileMode 14 modTime time.Time 15 isDir bool 16 } 17 18 func (i *fileInfo) Name() string { 19 return i.name 20 } 21 22 func (i *fileInfo) Size() int64 { 23 return i.size 24 } 25 func (i *fileInfo) Mode() os.FileMode { 26 return i.mode 27 } 28 func (i *fileInfo) ModTime() time.Time { 29 return i.modTime 30 } 31 32 func (i *fileInfo) IsDir() bool { 33 return i.isDir 34 } 35 36 func (i *fileInfo) Sys() interface{} { 37 return i 38 } 39 40 func NewFileInfo(name string, size int64, mode os.FileMode, modificationTime time.Time, isDir bool) os.FileInfo { 41 return &fileInfo{ 42 name: name, 43 size: size, 44 mode: mode, 45 modTime: modificationTime, 46 isDir: isDir, 47 } 48 } 49 50 func NewFileMode(fileAttributes string) (os.FileMode, error) { 51 var result os.FileMode 52 if len(fileAttributes) != 10 { 53 return result, fmt.Errorf("Invalid attribute length %v %v", fileAttributes, len(fileAttributes)) 54 } 55 56 const fileType = "dalTLDpSugct" 57 var fileModePosition = strings.Index(fileType, string(fileAttributes[0])) 58 if fileModePosition != -1 { 59 result = 1 << uint(32-1-fileModePosition) 60 } 61 62 const filePermission = "rwxrwxrwx" 63 for i, c := range filePermission { 64 if c == rune(fileAttributes[i+1]) { 65 result = result | 1<<uint(9-1-i) 66 } 67 } 68 return result, nil 69 70 }