8
8
)
9
9
10
10
var (
11
- ErrClosed = errors .New ("writing on closed file " )
12
- ErrReadOnly = errors .New ("read-only filesystem " )
13
- ErrNotSupported = errors .New ("feature not supported " )
11
+ ErrReadOnly = errors .New ("read-only filesystem " )
12
+ ErrNotSupported = errors .New ("feature not supported " )
13
+ ErrCrossedBoundary = errors .New ("chroot boundary crossed " )
14
14
)
15
15
16
16
// Filesystem abstract the operations in a storage-agnostic interface.
@@ -21,16 +21,22 @@ type Filesystem interface {
21
21
Dir
22
22
Symlink
23
23
TempFile
24
+ Chroot
25
+ }
24
26
25
- // Dir returns a new Filesystem from the same type of fs using as baseDir the
26
- // given path
27
- Dir (path string ) Filesystem
28
- // Base returns the base path of the filesystem
29
- Base () string
27
+ // Chroot abstract the chroot related operations in a storage-agnostic interface
28
+ // as an extension to the Basic interface.
29
+ type Chroot interface {
30
+ // Chroot returns a new filesystem from the same type where the new root is
31
+ // the given path. Files outside of the designated directory tree cannot be
32
+ // accessed.
33
+ Chroot (path string ) (Basic , error )
34
+ // Root returns the root path of the filesystem.
35
+ Root () string
30
36
}
31
37
32
38
// Basic abstract the basic operations in a storage-agnostic interface as
33
- // an extension to the Basic interface
39
+ // an extension to the Basic interface.
34
40
type Basic interface {
35
41
// Create creates the named file with mode 0666 (before umask), truncating
36
42
// it if it already exists. If successful, methods on the returned File can
@@ -49,7 +55,7 @@ type Basic interface {
49
55
OpenFile (filename string , flag int , perm os.FileMode ) (File , error )
50
56
// Stat returns a FileInfo describing the named file. If there is an error,
51
57
// it will be of type *PathError.
52
- Stat (filename string ) (FileInfo , error )
58
+ Stat (filename string ) (os. FileInfo , error )
53
59
// Rename renames (moves) oldpath to newpath. If newpath already exists and
54
60
// is not a directory, Rename replaces it. OS-specific restrictions may
55
61
// apply when oldpath and newpath are in different directories. If there is
@@ -74,7 +80,7 @@ type TempFile interface {
74
80
// Dir abstract the dir related operations in a storage-agnostic interface as
75
81
// an extension to the Basic interface.
76
82
type Dir interface {
77
- ReadDir (path string ) ([]FileInfo , error )
83
+ ReadDir (path string ) ([]os. FileInfo , error )
78
84
// MkdirAll creates a directory named path, along with any necessary
79
85
// parents, and returns nil, or else returns an error. The permission bits
80
86
// perm are used for all directories that MkdirAll creates. If path is/
@@ -89,7 +95,7 @@ type Symlink interface {
89
95
// symbolic link, the returned FileInfo describes the symbolic link. Lstat
90
96
// makes no attempt to follow the link. If there is an error, it will be of
91
97
// type *PathError.
92
- Lstat (filename string ) (FileInfo , error )
98
+ Lstat (filename string ) (os. FileInfo , error )
93
99
// Symlink creates a symbolic-link from link to target. target may be an
94
100
// absolute or relative path, and need not refer to an existing node.
95
101
// Parent directories of link are created as necessary. If there is an
@@ -123,32 +129,19 @@ type Change interface {
123
129
Chtimes (name string , atime time.Time , mtime time.Time ) error
124
130
}
125
131
126
- // File implements io.Closer, io.Reader, io.Seeker, and io.Writer>
127
- // Provides method to obtain the file name and the state of the file (open or closed).
132
+ // File represent a file, being a subset of the os.File
128
133
type File interface {
129
- Filename () string
130
- IsClosed () bool
134
+ // Name returns the name of the file as presented to Open.
135
+ Name () string
136
+ // Stat returns the FileInfo structure describing file. If there is an
137
+ // error, it will be of type *PathError.
138
+ // Stat() (os.FileInfo, error)
131
139
io.Writer
132
140
io.Reader
133
141
io.Seeker
134
142
io.Closer
135
143
}
136
144
137
- type FileInfo os.FileInfo
138
-
139
- type BaseFile struct {
140
- BaseFilename string
141
- Closed bool
142
- }
143
-
144
- func (f * BaseFile ) Filename () string {
145
- return f .BaseFilename
146
- }
147
-
148
- func (f * BaseFile ) IsClosed () bool {
149
- return f .Closed
150
- }
151
-
152
145
type removerAll interface {
153
146
RemoveAll (string ) error
154
147
}
0 commit comments