-
Notifications
You must be signed in to change notification settings - Fork 1
/
native.go
52 lines (43 loc) · 1012 Bytes
/
native.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"
)
type NativeFile struct{}
type NativeFileFactory struct{}
func (NativeFileFactory) Open(file string, args ...int) (FileDriver, error) {
flag := os.O_RDWR
mode := 0666
if len(args) > 0 {
if 0 == args[0] {
flag = os.O_RDWR | os.O_CREATE | os.O_TRUNC
} else {
flag = args[0]
}
if len(args) > 1 {
mode = args[0]
}
}
fd, err := os.OpenFile(file, flag, os.FileMode(mode))
return fd, err
}
func (NativeFileFactory) Rename(src, dst string) error {
return os.Rename(src, dst)
}
func (NativeFileFactory) Remove(file string) error {
return os.Remove(file)
}
func (NativeFileFactory) Exist(file string) bool {
if _, err := os.Stat(file); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func (NativeFileFactory) Mkdir(file string, mode int) error {
return os.MkdirAll(file, os.FileMode(mode))
}
func (NativeFileFactory) Walk(root string, callback filepath.WalkFunc) error {
return filepath.Walk(root, callback)
}