-
Notifications
You must be signed in to change notification settings - Fork 2
/
fs.go
75 lines (54 loc) · 1.53 KB
/
fs.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
69
70
71
72
73
74
75
// This file provides an interface to os functions used in dotbro.
package main
import "os"
// Interfaces
type OS interface {
Open(name string) (File, error)
Create(name string) (*os.File, error)
MkdirAll(path string, perm os.FileMode) error
Symlink(oldname, newname string) error
Readlink(name string) (string, error)
Stat(name string) (os.FileInfo, error)
Lstat(name string) (os.FileInfo, error)
IsNotExist(err error) bool
Rename(oldpath, newpath string) error
Remove(name string) error
}
type File interface {
Close() error
Stat() (os.FileInfo, error)
Readdir(n int) ([]os.FileInfo, error)
Read(p []byte) (n int, err error)
}
// Actual implementation of interface using os package.
type OSFS struct{}
func (f *OSFS) Open(name string) (File, error) {
return os.Open(name)
}
func (f *OSFS) Create(name string) (*os.File, error) {
return os.Create(name)
}
func (f *OSFS) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
func (f *OSFS) Symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
}
func (f *OSFS) Readlink(name string) (string, error) {
return os.Readlink(name)
}
func (f *OSFS) Stat(name string) (os.FileInfo, error) {
return os.Stat(name)
}
func (f *OSFS) Lstat(name string) (os.FileInfo, error) {
return os.Lstat(name)
}
func (f *OSFS) IsNotExist(err error) bool {
return os.IsNotExist(err)
}
func (f *OSFS) Rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath)
}
func (f *OSFS) Remove(name string) error {
return os.Remove(name)
}