github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/os/fsi/10_fs_interface.go (about) 1 package fsi 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 "time" 8 ) 9 10 var ( 11 // EmptyQueryResult is a warning, that implementations of ReadDir may return, 12 // if their results are based on weakly consistent indexes. 13 // It is defined here, since common.Walk() wants to ignore it. 14 EmptyQueryResult = fmt.Errorf("Query found no results based on weakly consistent index.") 15 16 // If an implementation cannot support a method, it should at least return this testable error. 17 NotImplemented = fmt.Errorf("Filesystem does not support this method.") 18 19 ErrRootDirNoFile = fmt.Errorf("rootdir; no file") 20 21 ErrFileClosed = errors.New("File is closed") 22 ErrFileInUse = errors.New("File already in use") 23 ErrOutOfRange = errors.New("Out of range") 24 ErrTooLarge = errors.New("Too large") 25 26 ErrFileNotFound = os.ErrNotExist 27 ErrFileExists = os.ErrExist 28 ErrDestinationExists = os.ErrExist 29 ) 30 31 // Interface FileSystem is inspired by os.File + io.ioutil, 32 // informed by godoc.vfs and package afero. 33 type FileSystem interface { 34 Name() string // the type of filesystem, i.e. "osfs" 35 String() string // a mountpoint or a drive letter 36 37 // Yes, interfaces should be as small as possible, but sooner or later you need these: 38 Chmod(name string, mode os.FileMode) error 39 Chtimes(name string, atime time.Time, mtime time.Time) error 40 41 Create(name string) (File, error) // read write 42 Lstat(path string) (os.FileInfo, error) // for common.Walk 43 Mkdir(name string, perm os.FileMode) error 44 MkdirAll(path string, perm os.FileMode) error 45 Open(name string) (File, error) // read only 46 OpenFile(name string, flag int, perm os.FileMode) (File, error) 47 48 // ReadDir is taken from io.ioutil. 49 // It should return directories first, then files second. 50 // Notice the distinct methods on File interface: 51 // Readdir(count int) ([]os.FileInfo, error) 52 // Readdirnames(n int) ([]string, error) 53 // Those coming from os.File. 54 // We base all those methods on a single internal implementation. 55 // Readdir may return EmptyQueryResult error as a warning. 56 // 57 // Compare File.Readdir remarks. 58 ReadDir(dirname string) ([]os.FileInfo, error) 59 60 Remove(name string) error 61 RemoveAll(path string) error 62 Rename(oldname, newname string) error 63 Stat(path string) (os.FileInfo, error) 64 65 SplitX(name string) (dir, bname string) // mostly but not entirely equivalent to path.Split() 66 67 // Two convenience methods taken from io.ioutil. 68 // They are mandatory, because you will need them sooner or later anyway. 69 // Thus we require them right from the start and with *standard* signatures. 70 ReadFile(filename string) ([]byte, error) 71 WriteFile(filename string, data []byte, perm os.FileMode) error 72 73 // Walk() is inspired by filepath.Walk() 74 // Walk is implemented generically, purely on fsi.FileSystem, 75 // in package common. Implementing it here is discouraged: 76 // Walk(root string, walkFn WalkFunc) error 77 78 }