forked from akrylysov/pogreb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.go
64 lines (51 loc) · 1.16 KB
/
os.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
package fs
import (
"io/ioutil"
"os"
)
type osFS struct{}
// OS is a file system backed by the os package.
var OS FileSystem = &osFS{}
func (fs *osFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
f, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, err
}
return &osFile{File: f}, nil
}
func (fs *osFS) CreateLockFile(name string, perm os.FileMode) (LockFile, bool, error) {
return createLockFile(name, perm)
}
func (fs *osFS) Stat(name string) (os.FileInfo, error) {
return os.Stat(name)
}
func (fs *osFS) Remove(name string) error {
return os.Remove(name)
}
func (fs *osFS) Rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath)
}
func (fs *osFS) ReadDir(name string) ([]os.FileInfo, error) {
return ioutil.ReadDir(name)
}
type osFile struct {
*os.File
}
func (f *osFile) Slice(start int64, end int64) ([]byte, error) {
buf := make([]byte, end-start)
_, err := f.ReadAt(buf, start)
if err != nil {
return nil, err
}
return buf, nil
}
type osLockFile struct {
*os.File
path string
}
func (f *osLockFile) Unlock() error {
if err := os.Remove(f.path); err != nil {
return err
}
return f.Close()
}