...
1
16
17 package container
18
19 import (
20 "os"
21 "path/filepath"
22 "time"
23 )
24
25
26
27 type OSInterface interface {
28 MkdirAll(path string, perm os.FileMode) error
29 Symlink(oldname string, newname string) error
30 Stat(path string) (os.FileInfo, error)
31 Remove(path string) error
32 RemoveAll(path string) error
33 Create(path string) (*os.File, error)
34 Chmod(path string, perm os.FileMode) error
35 Hostname() (name string, err error)
36 Chtimes(path string, atime time.Time, mtime time.Time) error
37 Pipe() (r *os.File, w *os.File, err error)
38 ReadDir(dirname string) ([]os.DirEntry, error)
39 Glob(pattern string) ([]string, error)
40 Open(name string) (*os.File, error)
41 OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
42 Rename(oldpath, newpath string) error
43 }
44
45
46 type RealOS struct{}
47
48
49 func (RealOS) MkdirAll(path string, perm os.FileMode) error {
50 return os.MkdirAll(path, perm)
51 }
52
53
54 func (RealOS) Symlink(oldname string, newname string) error {
55 return os.Symlink(oldname, newname)
56 }
57
58
59 func (RealOS) Stat(path string) (os.FileInfo, error) {
60 return os.Stat(path)
61 }
62
63
64 func (RealOS) Remove(path string) error {
65 return os.Remove(path)
66 }
67
68
69 func (RealOS) RemoveAll(path string) error {
70 return os.RemoveAll(path)
71 }
72
73
74
75 func (RealOS) Create(path string) (*os.File, error) {
76 return os.Create(path)
77 }
78
79
80
81 func (RealOS) Chmod(path string, perm os.FileMode) error {
82 return os.Chmod(path, perm)
83 }
84
85
86 func (RealOS) Hostname() (name string, err error) {
87 return os.Hostname()
88 }
89
90
91 func (RealOS) Chtimes(path string, atime time.Time, mtime time.Time) error {
92 return os.Chtimes(path, atime, mtime)
93 }
94
95
96 func (RealOS) Pipe() (r *os.File, w *os.File, err error) {
97 return os.Pipe()
98 }
99
100
101 func (RealOS) ReadDir(dirname string) ([]os.DirEntry, error) {
102 return os.ReadDir(dirname)
103 }
104
105
106
107 func (RealOS) Glob(pattern string) ([]string, error) {
108 return filepath.Glob(pattern)
109 }
110
111
112 func (RealOS) Open(name string) (*os.File, error) {
113 return os.Open(name)
114 }
115
116
117 func (RealOS) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
118 return os.OpenFile(name, flag, perm)
119 }
120
121
122 func (RealOS) Rename(oldpath, newpath string) error {
123 return os.Rename(oldpath, newpath)
124 }
125
View as plain text