Skip to content

Commit 0e32e1f

Browse files
committed
subdirfs & tmpfs: converted to helpers
1 parent d2e40d9 commit 0e32e1f

File tree

5 files changed

+27
-67
lines changed

5 files changed

+27
-67
lines changed

subdirfs/subdir.go renamed to helper/chroot/chroot.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package subdirfs
1+
package chroot
22

33
import (
44
"errors"
@@ -13,20 +13,20 @@ import (
1313
// underlying filesystem does not support symlinking.
1414
var ErrSymlinkNotSupported = errors.New("symlink not supported")
1515

16-
// SubDir is a helper to implement billy.Filesystem.Dir in other filesystems.
17-
type SubDir struct {
16+
// ChrootHelper is a helper to implement billy.Chroot.
17+
type ChrootHelper struct {
1818
underlying billy.Filesystem
1919
base string
2020
}
2121

2222
// New creates a new filesystem wrapping up the given 'fs'.
23-
// The created filesystem has its base in the given subdirectory of the
23+
// The created filesystem has its base in the given ChrootHelperectory of the
2424
// underlying filesystem.
2525
func New(fs billy.Filesystem, base string) billy.Filesystem {
26-
return &SubDir{fs, base}
26+
return &ChrootHelper{fs, base}
2727
}
2828

29-
func (fs *SubDir) underlyingPath(filename string) (string, error) {
29+
func (fs *ChrootHelper) underlyingPath(filename string) (string, error) {
3030
if isCrossBoundaries(filename) {
3131
return "", billy.ErrCrossedBoundary
3232
}
@@ -41,7 +41,7 @@ func isCrossBoundaries(path string) bool {
4141
return strings.HasPrefix(path, "..")
4242
}
4343

44-
func (fs *SubDir) Create(filename string) (billy.File, error) {
44+
func (fs *ChrootHelper) Create(filename string) (billy.File, error) {
4545
fullpath, err := fs.underlyingPath(filename)
4646
if err != nil {
4747
return nil, err
@@ -55,7 +55,7 @@ func (fs *SubDir) Create(filename string) (billy.File, error) {
5555
return newFile(fs, f, filename), nil
5656
}
5757

58-
func (fs *SubDir) Open(filename string) (billy.File, error) {
58+
func (fs *ChrootHelper) Open(filename string) (billy.File, error) {
5959
fullpath, err := fs.underlyingPath(filename)
6060
if err != nil {
6161
return nil, err
@@ -69,7 +69,7 @@ func (fs *SubDir) Open(filename string) (billy.File, error) {
6969
return newFile(fs, f, filename), nil
7070
}
7171

72-
func (fs *SubDir) OpenFile(filename string, flag int, mode os.FileMode) (billy.File, error) {
72+
func (fs *ChrootHelper) OpenFile(filename string, flag int, mode os.FileMode) (billy.File, error) {
7373
fullpath, err := fs.underlyingPath(filename)
7474
if err != nil {
7575
return nil, err
@@ -83,7 +83,7 @@ func (fs *SubDir) OpenFile(filename string, flag int, mode os.FileMode) (billy.F
8383
return newFile(fs, f, filename), nil
8484
}
8585

86-
func (fs *SubDir) TempFile(dir, prefix string) (billy.File, error) {
86+
func (fs *ChrootHelper) TempFile(dir, prefix string) (billy.File, error) {
8787
fullpath, err := fs.underlyingPath(dir)
8888
if err != nil {
8989
return nil, err
@@ -97,7 +97,7 @@ func (fs *SubDir) TempFile(dir, prefix string) (billy.File, error) {
9797
return newFile(fs, f, fs.Join(dir, filepath.Base(f.Name()))), nil
9898
}
9999

100-
func (fs *SubDir) Rename(from, to string) error {
100+
func (fs *ChrootHelper) Rename(from, to string) error {
101101
var err error
102102
from, err = fs.underlyingPath(from)
103103
if err != nil {
@@ -112,7 +112,7 @@ func (fs *SubDir) Rename(from, to string) error {
112112
return fs.underlying.Rename(from, to)
113113
}
114114

115-
func (fs *SubDir) Remove(path string) error {
115+
func (fs *ChrootHelper) Remove(path string) error {
116116
fullpath, err := fs.underlyingPath(path)
117117
if err != nil {
118118
return err
@@ -121,7 +121,7 @@ func (fs *SubDir) Remove(path string) error {
121121
return fs.underlying.Remove(fullpath)
122122
}
123123

124-
func (fs *SubDir) MkdirAll(filename string, perm os.FileMode) error {
124+
func (fs *ChrootHelper) MkdirAll(filename string, perm os.FileMode) error {
125125
fullpath, err := fs.underlyingPath(filename)
126126
if err != nil {
127127
return err
@@ -130,7 +130,7 @@ func (fs *SubDir) MkdirAll(filename string, perm os.FileMode) error {
130130
return fs.underlying.MkdirAll(fullpath, perm)
131131
}
132132

133-
func (fs *SubDir) Stat(filename string) (os.FileInfo, error) {
133+
func (fs *ChrootHelper) Stat(filename string) (os.FileInfo, error) {
134134
fullpath, err := fs.underlyingPath(filename)
135135
if err != nil {
136136
return nil, err
@@ -139,7 +139,7 @@ func (fs *SubDir) Stat(filename string) (os.FileInfo, error) {
139139
return fs.underlying.Stat(fullpath)
140140
}
141141

142-
func (fs *SubDir) Lstat(filename string) (os.FileInfo, error) {
142+
func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
143143
fullpath, err := fs.underlyingPath(filename)
144144
if err != nil {
145145
return nil, err
@@ -148,7 +148,7 @@ func (fs *SubDir) Lstat(filename string) (os.FileInfo, error) {
148148
return fs.underlying.Lstat(fullpath)
149149
}
150150

151-
func (fs *SubDir) ReadDir(path string) ([]os.FileInfo, error) {
151+
func (fs *ChrootHelper) ReadDir(path string) ([]os.FileInfo, error) {
152152
fullpath, err := fs.underlyingPath(path)
153153
if err != nil {
154154
return nil, err
@@ -157,11 +157,11 @@ func (fs *SubDir) ReadDir(path string) ([]os.FileInfo, error) {
157157
return fs.underlying.ReadDir(fullpath)
158158
}
159159

160-
func (fs *SubDir) Join(elem ...string) string {
160+
func (fs *ChrootHelper) Join(elem ...string) string {
161161
return fs.underlying.Join(elem...)
162162
}
163163

164-
func (fs *SubDir) Symlink(target, link string) error {
164+
func (fs *ChrootHelper) Symlink(target, link string) error {
165165
target = filepath.FromSlash(target)
166166

167167
// only rewrite target if it's already absolute
@@ -181,7 +181,7 @@ func (fs *SubDir) Symlink(target, link string) error {
181181
return fs.underlying.Symlink(target, link)
182182
}
183183

184-
func (fs *SubDir) isTargetOutBounders(link, target string) bool {
184+
func (fs *ChrootHelper) isTargetOutBounders(link, target string) bool {
185185
fulllink := fs.Join(fs.base, link)
186186
fullpath := fs.Join(filepath.Dir(fulllink), target)
187187
target, err := filepath.Rel(fs.base, fullpath)
@@ -192,7 +192,7 @@ func (fs *SubDir) isTargetOutBounders(link, target string) bool {
192192
return isCrossBoundaries(target)
193193
}
194194

195-
func (fs *SubDir) Readlink(link string) (string, error) {
195+
func (fs *ChrootHelper) Readlink(link string) (string, error) {
196196
fullpath, err := fs.underlyingPath(link)
197197
if err != nil {
198198
return "", err
@@ -216,7 +216,7 @@ func (fs *SubDir) Readlink(link string) (string, error) {
216216
return string(os.PathSeparator) + target, nil
217217
}
218218

219-
func (fs *SubDir) Chroot(path string) (billy.Basic, error) {
219+
func (fs *ChrootHelper) Chroot(path string) (billy.Basic, error) {
220220
fullpath, err := fs.underlyingPath(path)
221221
if err != nil {
222222
return nil, err
@@ -225,6 +225,6 @@ func (fs *SubDir) Chroot(path string) (billy.Basic, error) {
225225
return New(fs.underlying, fullpath), nil
226226
}
227227

228-
func (fs *SubDir) Root() string {
228+
func (fs *ChrootHelper) Root() string {
229229
return fs.base
230230
}

subdirfs/file.go renamed to helper/chroot/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package subdirfs
1+
package chroot
22

33
import (
44
"io"

tmpfs/tmpfs.go renamed to helper/temporal/tmpfs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tmpfs
1+
package temporal
22

33
import (
44
"errors"
@@ -8,7 +8,7 @@ import (
88
"path"
99

1010
"gopkg.in/src-d/go-billy.v2"
11-
"gopkg.in/src-d/go-billy.v2/subdirfs"
11+
"gopkg.in/src-d/go-billy.v2/helper/chroot"
1212
)
1313

1414
// Temporal provides billy.TempFile capabilities for filesystems that do not
@@ -151,7 +151,7 @@ func (fs *Temporal) Lstat(path string) (os.FileInfo, error) {
151151
}
152152

153153
func (fs *Temporal) Chroot(path string) (billy.Basic, error) {
154-
return subdirfs.New(fs, path), nil
154+
return chroot.New(fs, path), nil
155155
}
156156

157157
func (fs *Temporal) Root() string {

tmpfs/tmpfs_test.go renamed to helper/temporal/tmpfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tmpfs
1+
package temporal
22

33
import (
44
"io"

subdirfs/subdir_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)