Skip to content

Commit d2e40d9

Browse files
committed
*: Chroot interface and BaseFill removed
1 parent 15304c2 commit d2e40d9

File tree

15 files changed

+573
-334
lines changed

15 files changed

+573
-334
lines changed

fs.go

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
)
99

1010
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")
1414
)
1515

1616
// Filesystem abstract the operations in a storage-agnostic interface.
@@ -21,16 +21,22 @@ type Filesystem interface {
2121
Dir
2222
Symlink
2323
TempFile
24+
Chroot
25+
}
2426

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
3036
}
3137

3238
// 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.
3440
type Basic interface {
3541
// Create creates the named file with mode 0666 (before umask), truncating
3642
// it if it already exists. If successful, methods on the returned File can
@@ -49,7 +55,7 @@ type Basic interface {
4955
OpenFile(filename string, flag int, perm os.FileMode) (File, error)
5056
// Stat returns a FileInfo describing the named file. If there is an error,
5157
// it will be of type *PathError.
52-
Stat(filename string) (FileInfo, error)
58+
Stat(filename string) (os.FileInfo, error)
5359
// Rename renames (moves) oldpath to newpath. If newpath already exists and
5460
// is not a directory, Rename replaces it. OS-specific restrictions may
5561
// apply when oldpath and newpath are in different directories. If there is
@@ -74,7 +80,7 @@ type TempFile interface {
7480
// Dir abstract the dir related operations in a storage-agnostic interface as
7581
// an extension to the Basic interface.
7682
type Dir interface {
77-
ReadDir(path string) ([]FileInfo, error)
83+
ReadDir(path string) ([]os.FileInfo, error)
7884
// MkdirAll creates a directory named path, along with any necessary
7985
// parents, and returns nil, or else returns an error. The permission bits
8086
// perm are used for all directories that MkdirAll creates. If path is/
@@ -89,7 +95,7 @@ type Symlink interface {
8995
// symbolic link, the returned FileInfo describes the symbolic link. Lstat
9096
// makes no attempt to follow the link. If there is an error, it will be of
9197
// type *PathError.
92-
Lstat(filename string) (FileInfo, error)
98+
Lstat(filename string) (os.FileInfo, error)
9399
// Symlink creates a symbolic-link from link to target. target may be an
94100
// absolute or relative path, and need not refer to an existing node.
95101
// Parent directories of link are created as necessary. If there is an
@@ -123,32 +129,19 @@ type Change interface {
123129
Chtimes(name string, atime time.Time, mtime time.Time) error
124130
}
125131

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
128133
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)
131139
io.Writer
132140
io.Reader
133141
io.Seeker
134142
io.Closer
135143
}
136144

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-
152145
type removerAll interface {
153146
RemoveAll(string) error
154147
}

0 commit comments

Comments
 (0)