forked from opencontainers/umoci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fseval_default.go
140 lines (115 loc) · 3.92 KB
/
fseval_default.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016, 2017 SUSE LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package umoci
import (
"os"
"time"
"github.com/openSUSE/umoci/pkg/system"
"github.com/vbatts/go-mtree"
)
// DefaultFsEval is the "identity" form of FsEval. In particular, it does not
// do any trickery and calls directly to the relevant os.* functions (and does
// not wrap KeywordFunc). This should be used by default, because there are no
// weird side-effects.
var DefaultFsEval FsEval = osFsEval(0)
// osFsEval is a hack to be able to make DefaultFsEval a const.
type osFsEval int
// Open is equivalent to os.Open.
func (fs osFsEval) Open(path string) (*os.File, error) {
return os.Open(path)
}
// Create is equivalent to os.Create.
func (fs osFsEval) Create(path string) (*os.File, error) {
return os.Create(path)
}
// Readdir is equivalent to os.Readdir.
func (fs osFsEval) Readdir(path string) ([]os.FileInfo, error) {
fh, err := os.Open(path)
if err != nil {
return nil, err
}
defer fh.Close()
return fh.Readdir(-1)
}
// Lstat is equivalent to os.Lstat.
func (fs osFsEval) Lstat(path string) (os.FileInfo, error) {
return os.Lstat(path)
}
// Readlink is equivalent to os.Readlink.
func (fs osFsEval) Readlink(path string) (string, error) {
return os.Readlink(path)
}
// Symlink is equivalent to os.Symlink.
func (fs osFsEval) Symlink(linkname, path string) error {
return os.Symlink(linkname, path)
}
// Link is equivalent to os.Link.
func (fs osFsEval) Link(linkname, path string) error {
return os.Link(linkname, path)
}
// Chmod is equivalent to os.Chmod.
func (fs osFsEval) Chmod(path string, mode os.FileMode) error {
return os.Chmod(path, mode)
}
// Lutimes is equivalent to os.Lutimes.
func (fs osFsEval) Lutimes(path string, atime, mtime time.Time) error {
return system.Lutimes(path, atime, mtime)
}
// Remove is equivalent to os.Remove.
func (fs osFsEval) Remove(path string) error {
return os.Remove(path)
}
// RemoveAll is equivalent to os.RemoveAll.
func (fs osFsEval) RemoveAll(path string) error {
return os.RemoveAll(path)
}
// Mkdir is equivalent to os.Mkdir.
func (fs osFsEval) Mkdir(path string, perm os.FileMode) error {
return os.Mkdir(path, perm)
}
// Mknod is equivalent to system.Mknod.
func (fs osFsEval) Mknod(path string, mode os.FileMode, dev system.Dev_t) error {
return system.Mknod(path, mode, dev)
}
// MkdirAll is equivalent to os.MkdirAll.
func (fs osFsEval) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
// Llistxattr is equivalent to system.Llistxattr
func (fs osFsEval) Llistxattr(path string) ([]string, error) {
return system.Llistxattr(path)
}
// Lremovexattr is equivalent to system.Lremovexattr
func (fs osFsEval) Lremovexattr(path, name string) error {
return system.Lremovexattr(path, name)
}
// Lsetxattr is equivalent to system.Lsetxattr
func (fs osFsEval) Lsetxattr(path, name string, value []byte, flags int) error {
return system.Lsetxattr(path, name, value, flags)
}
// Lgetxattr is equivalent to system.Lgetxattr
func (fs osFsEval) Lgetxattr(path string, name string) ([]byte, error) {
return system.Lgetxattr(path, name)
}
// Lclearxattrs is equivalent to system.Lclearxattrs
func (fs osFsEval) Lclearxattrs(path string) error {
return system.Lclearxattrs(path)
}
// KeywordFunc returns a wrapper around the given mtree.KeywordFunc.
func (fs osFsEval) KeywordFunc(fn mtree.KeywordFunc) mtree.KeywordFunc {
return fn
}