forked from akrylysov/pogreb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.go
52 lines (42 loc) · 1.19 KB
/
sub.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
package fs
import (
"os"
"path/filepath"
)
// Sub returns a new file system rooted at dir.
func Sub(fsys FileSystem, dir string) FileSystem {
return &subFS{
fsys: fsys,
root: dir,
}
}
type subFS struct {
fsys FileSystem
root string
}
func (fs *subFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
subName := filepath.Join(fs.root, name)
return fs.fsys.OpenFile(subName, flag, perm)
}
func (fs *subFS) Stat(name string) (os.FileInfo, error) {
subName := filepath.Join(fs.root, name)
return fs.fsys.Stat(subName)
}
func (fs *subFS) Remove(name string) error {
subName := filepath.Join(fs.root, name)
return fs.fsys.Remove(subName)
}
func (fs *subFS) Rename(oldpath, newpath string) error {
subOldpath := filepath.Join(fs.root, oldpath)
subNewpath := filepath.Join(fs.root, newpath)
return fs.fsys.Rename(subOldpath, subNewpath)
}
func (fs *subFS) ReadDir(name string) ([]os.FileInfo, error) {
subName := filepath.Join(fs.root, name)
return fs.fsys.ReadDir(subName)
}
func (fs *subFS) CreateLockFile(name string, perm os.FileMode) (LockFile, bool, error) {
subName := filepath.Join(fs.root, name)
return fs.fsys.CreateLockFile(subName, perm)
}
var _ FileSystem = &subFS{}