-
Notifications
You must be signed in to change notification settings - Fork 36
/
file_system_interface.go
68 lines (53 loc) · 2.16 KB
/
file_system_interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package system
import (
"io"
"os"
"path/filepath"
)
// File is a subset of os.File
type File interface {
io.ReadWriteCloser
ReadAt([]byte, int64) (int, error)
WriteAt([]byte, int64) (int, error)
Seek(int64, int) (int64, error)
Stat() (os.FileInfo, error)
Name() string
}
type FileSystem interface {
HomeDir(username string) (path string, err error)
ExpandPath(path string) (expandedPath string, err error)
// MkdirAll will not change existing dir permissions
// if dir exists and has different permissions
MkdirAll(path string, perm os.FileMode) error
RemoveAll(fileOrDir string) error
Chown(path, username string) error
Chmod(path string, perm os.FileMode) error
OpenFile(path string, flag int, perm os.FileMode) (File, error)
WriteFileString(path, content string) error
WriteFile(path string, content []byte) error
WriteFileQuietly(path string, content []byte) error
ConvergeFileContents(path string, content []byte, opts ...ConvergeFileContentsOpts) (written bool, err error)
ReadFileString(path string) (content string, err error)
ReadFile(path string) (content []byte, err error)
ReadFileWithOpts(path string, opts ReadOpts) (content []byte, err error)
FileExists(path string) bool
Stat(path string) (os.FileInfo, error)
StatWithOpts(path string, opts StatOpts) (os.FileInfo, error)
Lstat(path string) (os.FileInfo, error)
Rename(oldPath, newPath string) error
// After Symlink file at newPath will be pointing to file at oldPath.
// Symlink call will remove file at newPath if one exists
// to make newPath a symlink to the file at oldPath.
Symlink(oldPath, newPath string) error
ReadAndFollowLink(symlinkPath string) (targetPath string, err error)
Readlink(symlinkPath string) (targetPath string, err error)
CopyFile(srcPath, dstPath string) error
CopyDir(srcPath, dstPath string) error
// Returns *unique* temporary file/dir with a custom prefix
TempFile(prefix string) (file File, err error)
TempDir(prefix string) (path string, err error)
ChangeTempRoot(path string) error
Glob(pattern string) (matches []string, err error)
RecursiveGlob(pattern string) (matches []string, err error)
Walk(root string, walkFunc filepath.WalkFunc) error
}