1package driver 2 3import "time" 4 5// FileInfo returns information about a given path. Inspired by os.FileInfo, 6// it elides the base name method for a full path instead. 7type FileInfo interface { 8 // Path provides the full path of the target of this file info. 9 Path() string 10 11 // Size returns current length in bytes of the file. The return value can 12 // be used to write to the end of the file at path. The value is 13 // meaningless if IsDir returns true. 14 Size() int64 15 16 // ModTime returns the modification time for the file. For backends that 17 // don't have a modification time, the creation time should be returned. 18 ModTime() time.Time 19 20 // IsDir returns true if the path is a directory. 21 IsDir() bool 22} 23 24// NOTE(stevvooe): The next two types, FileInfoFields and FileInfoInternal 25// should only be used by storagedriver implementations. They should moved to 26// a "driver" package, similar to database/sql. 27 28// FileInfoFields provides the exported fields for implementing FileInfo 29// interface in storagedriver implementations. It should be used with 30// InternalFileInfo. 31type FileInfoFields struct { 32 // Path provides the full path of the target of this file info. 33 Path string 34 35 // Size is current length in bytes of the file. The value of this field 36 // can be used to write to the end of the file at path. The value is 37 // meaningless if IsDir is set to true. 38 Size int64 39 40 // ModTime returns the modification time for the file. For backends that 41 // don't have a modification time, the creation time should be returned. 42 ModTime time.Time 43 44 // IsDir returns true if the path is a directory. 45 IsDir bool 46} 47 48// FileInfoInternal implements the FileInfo interface. This should only be 49// used by storagedriver implementations that don't have a specialized 50// FileInfo type. 51type FileInfoInternal struct { 52 FileInfoFields 53} 54 55var _ FileInfo = FileInfoInternal{} 56var _ FileInfo = &FileInfoInternal{} 57 58// Path provides the full path of the target of this file info. 59func (fi FileInfoInternal) Path() string { 60 return fi.FileInfoFields.Path 61} 62 63// Size returns current length in bytes of the file. The return value can 64// be used to write to the end of the file at path. The value is 65// meaningless if IsDir returns true. 66func (fi FileInfoInternal) Size() int64 { 67 return fi.FileInfoFields.Size 68} 69 70// ModTime returns the modification time for the file. For backends that 71// don't have a modification time, the creation time should be returned. 72func (fi FileInfoInternal) ModTime() time.Time { 73 return fi.FileInfoFields.ModTime 74} 75 76// IsDir returns true if the path is a directory. 77func (fi FileInfoInternal) IsDir() bool { 78 return fi.FileInfoFields.IsDir 79} 80