Skip to content

Commit

Permalink
*: add L*xattr to FsEval
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksa Sarai <asarai@suse.com>
  • Loading branch information
cyphar committed Dec 17, 2016
1 parent 1f726db commit 2824667
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 40 deletions.
41 changes: 28 additions & 13 deletions fseval.go
Expand Up @@ -33,48 +33,63 @@ var _ mtree.FsEval = RootlessFsEval
// mtree.FsEval as well as including all of the imporant os.* wrapper functions
// needed for "oci/layers".tarExtractor.
type FsEval interface {
// Open is a wrapper around unpriv.Open.
// Open is equivalent to os.Open.
Open(path string) (*os.File, error)

// Create is a wrapper around unpriv.Create.
// Create is equivalent to os.Create.
Create(path string) (*os.File, error)

// Readdir is a wrapper around unpriv.Readdir.
// Readdir is equivalent to os.Readdir.
Readdir(path string) ([]os.FileInfo, error)

// Lstat is a wrapper around unpriv.Lstat.
// Lstat is equivalent to os.Lstat.
Lstat(path string) (os.FileInfo, error)

// Readlink is a wrapper around unpriv.Readlink.
// Readlink is equivalent to os.Readlink.
Readlink(path string) (string, error)

// Symlink is a wrapper around unpriv.Symlink.
// Symlink is equivalent to os.Symlink.
Symlink(linkname, path string) error

// Link is a wrapper around unpriv.Link.
// Link is equivalent to os.Link.
Link(linkname, path string) error

// Chmod is a wrapper around unpriv.Chmod.
// Chmod is equivalent to os.Chmod.
Chmod(path string, mode os.FileMode) error

// Lutimes is a wrapper around unpriv.Lutimes.
// Lutimes is equivalent to os.Lutimes.
Lutimes(path string, atime, mtime time.Time) error

// Remove is a wrapper around unpriv.Remove.
// Remove is equivalent to os.Remove.
Remove(path string) error

// RemoveAll is a wrapper around unpriv.RemoveAll.
// RemoveAll is equivalent to os.RemoveAll.
RemoveAll(path string) error

// Mkdir is a wrapper around unpriv.Mkdir.
// Mkdir is equivalent to os.Mkdir.
Mkdir(path string, perm os.FileMode) error

// MkdirAll is a wrapper around unpriv.MkdirAll.
// MkdirAll is equivalent to os.MkdirAll.
MkdirAll(path string, perm os.FileMode) error

// Mknod is equivalent to system.Mknod.
Mknod(path string, mode os.FileMode, dev system.Dev_t) error

// Llistxattr is equivalent to system.Llistxattr
Llistxattr(path string) ([]string, error)

// Lremovexattr is equivalent to system.Lremovexattr
Lremovexattr(path, name string) error

// Lsetxattr is equivalent to system.Lsetxattr
Lsetxattr(path, name string, value []byte, flags int) error

// Lgetxattr is equivalent to system.Lgetxattr
Lgetxattr(path string, name string) ([]byte, error)

// Lclearxattrs is equivalent to system.Lclearxattrs
Lclearxattrs(path string) error

// KeywordFunc returns a wrapper around the given mtree.KeywordFunc.
KeywordFunc(fn mtree.KeywordFunc) mtree.KeywordFunc
}
53 changes: 39 additions & 14 deletions fseval_default.go
Expand Up @@ -31,20 +31,20 @@ import (
// weird side-effects.
var DefaultFsEval FsEval = osFsEval(0)

// unprivFsEval is a hack to be able to make DefaultFsEval a const.
// osFsEval is a hack to be able to make DefaultFsEval a const.
type osFsEval int

// Open is a wrapper around unpriv.Open.
// Open is equivalent to os.Open.
func (fs osFsEval) Open(path string) (*os.File, error) {
return os.Open(path)
}

// Create is a wrapper around unpriv.Create.
// Create is equivalent to os.Create.
func (fs osFsEval) Create(path string) (*os.File, error) {
return os.Create(path)
}

// Readdir is a wrapper around unpriv.Readdir.
// Readdir is equivalent to os.Readdir.
func (fs osFsEval) Readdir(path string) ([]os.FileInfo, error) {
fh, err := os.Open(path)
if err != nil {
Expand All @@ -54,47 +54,47 @@ func (fs osFsEval) Readdir(path string) ([]os.FileInfo, error) {
return fh.Readdir(-1)
}

// Lstat is a wrapper around unpriv.Lstat.
// Lstat is equivalent to os.Lstat.
func (fs osFsEval) Lstat(path string) (os.FileInfo, error) {
return os.Lstat(path)
}

// Readlink is a wrapper around unpriv.Readlink.
// Readlink is equivalent to os.Readlink.
func (fs osFsEval) Readlink(path string) (string, error) {
return os.Readlink(path)
}

// Symlink is a wrapper around unpriv.Symlink.
// Symlink is equivalent to os.Symlink.
func (fs osFsEval) Symlink(linkname, path string) error {
return os.Symlink(linkname, path)
}

// Link is a wrapper around unpriv.Link.
// Link is equivalent to os.Link.
func (fs osFsEval) Link(linkname, path string) error {
return os.Link(linkname, path)
}

// Chmod is a wrapper around unpriv.Chmod.
// Chmod is equivalent to os.Chmod.
func (fs osFsEval) Chmod(path string, mode os.FileMode) error {
return os.Chmod(path, mode)
}

// Lutimes is a wrapper around unpriv.Lutimes.
// 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 a wrapper around unpriv.Remove.
// Remove is equivalent to os.Remove.
func (fs osFsEval) Remove(path string) error {
return os.Remove(path)
}

// RemoveAll is a wrapper around unpriv.RemoveAll.
// RemoveAll is equivalent to os.RemoveAll.
func (fs osFsEval) RemoveAll(path string) error {
return os.RemoveAll(path)
}

// Mkdir is a wrapper around unpriv.Mkdir.
// Mkdir is equivalent to os.Mkdir.
func (fs osFsEval) Mkdir(path string, perm os.FileMode) error {
return os.Mkdir(path, perm)
}
Expand All @@ -104,11 +104,36 @@ func (fs osFsEval) Mknod(path string, mode os.FileMode, dev system.Dev_t) error
return system.Mknod(path, mode, dev)
}

// MkdirAll is a wrapper around unpriv.MkdirAll.
// 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
Expand Down
51 changes: 38 additions & 13 deletions fseval_rootless.go
Expand Up @@ -37,62 +37,62 @@ var RootlessFsEval FsEval = unprivFsEval(0)
// unprivFsEval is a hack to be able to make RootlessFsEval a const.
type unprivFsEval int

// Open is a wrapper around unpriv.Open.
// Open is equivalent to unpriv.Open.
func (fs unprivFsEval) Open(path string) (*os.File, error) {
return unpriv.Open(path)
}

// Create is a wrapper around unpriv.Create.
// Create is equivalent to unpriv.Create.
func (fs unprivFsEval) Create(path string) (*os.File, error) {
return unpriv.Create(path)
}

// Readdir is a wrapper around unpriv.Readdir.
// Readdir is equivalent to unpriv.Readdir.
func (fs unprivFsEval) Readdir(path string) ([]os.FileInfo, error) {
return unpriv.Readdir(path)
}

// Lstat is a wrapper around unpriv.Lstat.
// Lstat is equivalent to unpriv.Lstat.
func (fs unprivFsEval) Lstat(path string) (os.FileInfo, error) {
return unpriv.Lstat(path)
}

// Readlink is a wrapper around unpriv.Readlink.
// Readlink is equivalent to unpriv.Readlink.
func (fs unprivFsEval) Readlink(path string) (string, error) {
return unpriv.Readlink(path)
}

// Symlink is a wrapper around unpriv.Symlink.
// Symlink is equivalent to unpriv.Symlink.
func (fs unprivFsEval) Symlink(linkname, path string) error {
return unpriv.Symlink(linkname, path)
}

// Link is a wrapper around unpriv.Link.
// Link is equivalent to unpriv.Link.
func (fs unprivFsEval) Link(linkname, path string) error {
return unpriv.Link(linkname, path)
}

// Chmod is a wrapper around unpriv.Chmod.
// Chmod is equivalent to unpriv.Chmod.
func (fs unprivFsEval) Chmod(path string, mode os.FileMode) error {
return unpriv.Chmod(path, mode)
}

// Lutimes is a wrapper around unpriv.Lutimes.
// Lutimes is equivalent to unpriv.Lutimes.
func (fs unprivFsEval) Lutimes(path string, atime, mtime time.Time) error {
return unpriv.Lutimes(path, atime, mtime)
}

// Remove is a wrapper around unpriv.Remove.
// Remove is equivalent to unpriv.Remove.
func (fs unprivFsEval) Remove(path string) error {
return unpriv.Remove(path)
}

// RemoveAll is a wrapper around unpriv.RemoveAll.
// RemoveAll is equivalent to unpriv.RemoveAll.
func (fs unprivFsEval) RemoveAll(path string) error {
return unpriv.RemoveAll(path)
}

// Mkdir is a wrapper around unpriv.Mkdir.
// Mkdir is equivalent to unpriv.Mkdir.
func (fs unprivFsEval) Mkdir(path string, perm os.FileMode) error {
return unpriv.Mkdir(path, perm)
}
Expand All @@ -102,11 +102,36 @@ func (fs unprivFsEval) Mknod(path string, mode os.FileMode, dev system.Dev_t) er
return unpriv.Mknod(path, mode, dev)
}

// MkdirAll is a wrapper around unpriv.MkdirAll.
// MkdirAll is equivalent to unpriv.MkdirAll.
func (fs unprivFsEval) MkdirAll(path string, perm os.FileMode) error {
return unpriv.MkdirAll(path, perm)
}

// Llistxattr is equivalent to unpriv.Llistxattr
func (fs unprivFsEval) Llistxattr(path string) ([]string, error) {
return unpriv.Llistxattr(path)
}

// Lremovexattr is equivalent to unpriv.Lremovexattr
func (fs unprivFsEval) Lremovexattr(path, name string) error {
return unpriv.Lremovexattr(path, name)
}

// Lsetxattr is equivalent to unpriv.Lsetxattr
func (fs unprivFsEval) Lsetxattr(path, name string, value []byte, flags int) error {
return unpriv.Lsetxattr(path, name, value, flags)
}

// Lgetxattr is equivalent to unpriv.Lgetxattr
func (fs unprivFsEval) Lgetxattr(path string, name string) ([]byte, error) {
return unpriv.Lgetxattr(path, name)
}

// Lclearxattrs is equivalent to unpriv.Lclearxattrs
func (fs unprivFsEval) Lclearxattrs(path string) error {
return unpriv.Lclearxattrs(path)
}

// KeywordFunc returns a wrapper around the given mtree.KeywordFunc.
func (fs unprivFsEval) KeywordFunc(fn mtree.KeywordFunc) mtree.KeywordFunc {
return func(path string, info os.FileInfo, r io.Reader) (mtree.KeyVal, error) {
Expand Down

0 comments on commit 2824667

Please sign in to comment.