1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
17 package files
18
19 import (
20 "os"
21 )
22
23
24 func OSFS() VFS {
25 return osFS{}
26 }
27
28
29
30 type osFS struct{}
31
32 func (osFS) Remove(path string) error { return os.Remove(path) }
33 func (osFS) RemoveDir(path string) error { return os.Remove(path) }
34 func (osFS) Stat(path string) (os.FileInfo, error) { return os.Stat(path) }
35 func (osFS) Lstat(path string) (os.FileInfo, error) { return os.Lstat(path) }
36 func (osFS) Open(path string) (ReadableFile, error) { return os.Open(path) }
37 func (osFS) MkdirAll(path string, perm os.FileMode) error { return os.MkdirAll(path, perm) }
38
39 func (osFS) Rename(oldname, newname string) error {
40 err := os.Rename(oldname, newname)
41 if err != nil {
42 err = mapRenameError(err, oldname, newname)
43 }
44 return err
45 }
46
47 func (osFS) TempFile(dir, prefix string) (WritableFile, error) {
48 f, err := os.CreateTemp(dir, prefix)
49 if err != nil {
50 return nil, err
51 }
52 return f, nil
53 }
54
55 func (osFS) ReadDirNames(dir string) ([]string, error) {
56 d, err := os.Open(dir)
57 if err != nil {
58 return nil, err
59 }
60 defer d.Close()
61 return d.Readdirnames(-1)
62 }