mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	
							
								
								
									
										174
									
								
								vendor/github.com/containerd/continuity/driver/driver.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								vendor/github.com/containerd/continuity/driver/driver.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,174 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var ErrNotSupported = fmt.Errorf("not supported")
 | 
			
		||||
 | 
			
		||||
// Driver provides all of the system-level functions in a common interface.
 | 
			
		||||
// The context should call these with full paths and should never use the `os`
 | 
			
		||||
// package or any other package to access resources on the filesystem. This
 | 
			
		||||
// mechanism let's us carefully control access to the context and maintain
 | 
			
		||||
// path and resource integrity. It also gives us an interface to reason about
 | 
			
		||||
// direct resource access.
 | 
			
		||||
//
 | 
			
		||||
// Implementations don't need to do much other than meet the interface. For
 | 
			
		||||
// example, it is not required to wrap os.FileInfo to return correct paths for
 | 
			
		||||
// the call to Name().
 | 
			
		||||
type Driver interface {
 | 
			
		||||
	// Note that Open() returns a File interface instead of *os.File. This
 | 
			
		||||
	// is because os.File is a struct, so if Open was to return *os.File,
 | 
			
		||||
	// the only way to fulfill the interface would be to call os.Open()
 | 
			
		||||
	Open(path string) (File, error)
 | 
			
		||||
	OpenFile(path string, flag int, perm os.FileMode) (File, error)
 | 
			
		||||
 | 
			
		||||
	Stat(path string) (os.FileInfo, error)
 | 
			
		||||
	Lstat(path string) (os.FileInfo, error)
 | 
			
		||||
	Readlink(p string) (string, error)
 | 
			
		||||
	Mkdir(path string, mode os.FileMode) error
 | 
			
		||||
	Remove(path string) error
 | 
			
		||||
 | 
			
		||||
	Link(oldname, newname string) error
 | 
			
		||||
	Lchmod(path string, mode os.FileMode) error
 | 
			
		||||
	Lchown(path string, uid, gid int64) error
 | 
			
		||||
	Symlink(oldname, newname string) error
 | 
			
		||||
 | 
			
		||||
	MkdirAll(path string, perm os.FileMode) error
 | 
			
		||||
	RemoveAll(path string) error
 | 
			
		||||
 | 
			
		||||
	// TODO(aaronl): These methods might move outside the main Driver
 | 
			
		||||
	// interface in the future as more platforms are added.
 | 
			
		||||
	Mknod(path string, mode os.FileMode, major int, minor int) error
 | 
			
		||||
	Mkfifo(path string, mode os.FileMode) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// File is the interface for interacting with files returned by continuity's Open
 | 
			
		||||
// This is needed since os.File is a struct, instead of an interface, so it can't
 | 
			
		||||
// be used.
 | 
			
		||||
type File interface {
 | 
			
		||||
	io.ReadWriteCloser
 | 
			
		||||
	io.Seeker
 | 
			
		||||
	Readdir(n int) ([]os.FileInfo, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewSystemDriver() (Driver, error) {
 | 
			
		||||
	// TODO(stevvooe): Consider having this take a "hint" path argument, which
 | 
			
		||||
	// would be the context root. The hint could be used to resolve required
 | 
			
		||||
	// filesystem support when assembling the driver to use.
 | 
			
		||||
	return &driver{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// XAttrDriver should be implemented on operation systems and filesystems that
 | 
			
		||||
// have xattr support for regular files and directories.
 | 
			
		||||
type XAttrDriver interface {
 | 
			
		||||
	// Getxattr returns all of the extended attributes for the file at path.
 | 
			
		||||
	// Typically, this takes a syscall call to Listxattr and Getxattr.
 | 
			
		||||
	Getxattr(path string) (map[string][]byte, error)
 | 
			
		||||
 | 
			
		||||
	// Setxattr sets all of the extended attributes on file at path, following
 | 
			
		||||
	// any symbolic links, if necessary. All attributes on the target are
 | 
			
		||||
	// replaced by the values from attr. If the operation fails to set any
 | 
			
		||||
	// attribute, those already applied will not be rolled back.
 | 
			
		||||
	Setxattr(path string, attr map[string][]byte) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LXAttrDriver should be implemented by drivers on operating systems and
 | 
			
		||||
// filesystems that support setting and getting extended attributes on
 | 
			
		||||
// symbolic links. If this is not implemented, extended attributes will be
 | 
			
		||||
// ignored on symbolic links.
 | 
			
		||||
type LXAttrDriver interface {
 | 
			
		||||
	// LGetxattr returns all of the extended attributes for the file at path
 | 
			
		||||
	// and does not follow symlinks. Typically, this takes a syscall call to
 | 
			
		||||
	// Llistxattr and Lgetxattr.
 | 
			
		||||
	LGetxattr(path string) (map[string][]byte, error)
 | 
			
		||||
 | 
			
		||||
	// LSetxattr sets all of the extended attributes on file at path, without
 | 
			
		||||
	// following symbolic links. All attributes on the target are replaced by
 | 
			
		||||
	// the values from attr. If the operation fails to set any attribute,
 | 
			
		||||
	// those already applied will not be rolled back.
 | 
			
		||||
	LSetxattr(path string, attr map[string][]byte) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DeviceInfoDriver interface {
 | 
			
		||||
	DeviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// driver is a simple default implementation that sends calls out to the "os"
 | 
			
		||||
// package. Extend the "driver" type in system-specific files to add support,
 | 
			
		||||
// such as xattrs, which can add support at compile time.
 | 
			
		||||
type driver struct{}
 | 
			
		||||
 | 
			
		||||
var _ File = &os.File{}
 | 
			
		||||
 | 
			
		||||
// LocalDriver is the exported Driver struct for convenience.
 | 
			
		||||
var LocalDriver Driver = &driver{}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Open(p string) (File, error) {
 | 
			
		||||
	return os.Open(p)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) OpenFile(path string, flag int, perm os.FileMode) (File, error) {
 | 
			
		||||
	return os.OpenFile(path, flag, perm)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Stat(p string) (os.FileInfo, error) {
 | 
			
		||||
	return os.Stat(p)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Lstat(p string) (os.FileInfo, error) {
 | 
			
		||||
	return os.Lstat(p)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Mkdir(p string, mode os.FileMode) error {
 | 
			
		||||
	return os.Mkdir(p, mode)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Remove is used to unlink files and remove directories.
 | 
			
		||||
// This is following the golang os package api which
 | 
			
		||||
// combines the operations into a higher level Remove
 | 
			
		||||
// function. If explicit unlinking or directory removal
 | 
			
		||||
// to mirror system call is required, they should be
 | 
			
		||||
// split up at that time.
 | 
			
		||||
func (d *driver) Remove(path string) error {
 | 
			
		||||
	return os.Remove(path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Link(oldname, newname string) error {
 | 
			
		||||
	return os.Link(oldname, newname)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Lchown(name string, uid, gid int64) error {
 | 
			
		||||
	// TODO: error out if uid excesses int bit width?
 | 
			
		||||
	return os.Lchown(name, int(uid), int(gid))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Symlink(oldname, newname string) error {
 | 
			
		||||
	return os.Symlink(oldname, newname)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) MkdirAll(path string, perm os.FileMode) error {
 | 
			
		||||
	return os.MkdirAll(path, perm)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) RemoveAll(path string) error {
 | 
			
		||||
	return os.RemoveAll(path)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										138
									
								
								vendor/github.com/containerd/continuity/driver/driver_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								vendor/github.com/containerd/continuity/driver/driver_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,138 @@
 | 
			
		||||
// +build linux darwin freebsd solaris
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sort"
 | 
			
		||||
 | 
			
		||||
	"github.com/containerd/continuity/devices"
 | 
			
		||||
	"github.com/containerd/continuity/sysx"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
 | 
			
		||||
	err := devices.Mknod(path, mode, major, minor)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		err = &os.PathError{Op: "mknod", Path: path, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Mkfifo(path string, mode os.FileMode) error {
 | 
			
		||||
	if mode&os.ModeNamedPipe == 0 {
 | 
			
		||||
		return errors.New("mode passed to Mkfifo does not have the named pipe bit set")
 | 
			
		||||
	}
 | 
			
		||||
	// mknod with a mode that has ModeNamedPipe set creates a fifo, not a
 | 
			
		||||
	// device.
 | 
			
		||||
	err := devices.Mknod(path, mode, 0, 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		err = &os.PathError{Op: "mkfifo", Path: path, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Getxattr returns all of the extended attributes for the file at path p.
 | 
			
		||||
func (d *driver) Getxattr(p string) (map[string][]byte, error) {
 | 
			
		||||
	xattrs, err := sysx.Listxattr(p)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("listing %s xattrs: %v", p, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sort.Strings(xattrs)
 | 
			
		||||
	m := make(map[string][]byte, len(xattrs))
 | 
			
		||||
 | 
			
		||||
	for _, attr := range xattrs {
 | 
			
		||||
		value, err := sysx.Getxattr(p, attr)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("getting %q xattr on %s: %v", attr, p, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// NOTE(stevvooe): This append/copy tricky relies on unique
 | 
			
		||||
		// xattrs. Break this out into an alloc/copy if xattrs are no
 | 
			
		||||
		// longer unique.
 | 
			
		||||
		m[attr] = append(m[attr], value...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return m, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Setxattr sets all of the extended attributes on file at path, following
 | 
			
		||||
// any symbolic links, if necessary. All attributes on the target are
 | 
			
		||||
// replaced by the values from attr. If the operation fails to set any
 | 
			
		||||
// attribute, those already applied will not be rolled back.
 | 
			
		||||
func (d *driver) Setxattr(path string, attrMap map[string][]byte) error {
 | 
			
		||||
	for attr, value := range attrMap {
 | 
			
		||||
		if err := sysx.Setxattr(path, attr, value, 0); err != nil {
 | 
			
		||||
			return fmt.Errorf("error setting xattr %q on %s: %v", attr, path, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LGetxattr returns all of the extended attributes for the file at path p
 | 
			
		||||
// not following symbolic links.
 | 
			
		||||
func (d *driver) LGetxattr(p string) (map[string][]byte, error) {
 | 
			
		||||
	xattrs, err := sysx.LListxattr(p)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("listing %s xattrs: %v", p, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sort.Strings(xattrs)
 | 
			
		||||
	m := make(map[string][]byte, len(xattrs))
 | 
			
		||||
 | 
			
		||||
	for _, attr := range xattrs {
 | 
			
		||||
		value, err := sysx.LGetxattr(p, attr)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("getting %q xattr on %s: %v", attr, p, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// NOTE(stevvooe): This append/copy tricky relies on unique
 | 
			
		||||
		// xattrs. Break this out into an alloc/copy if xattrs are no
 | 
			
		||||
		// longer unique.
 | 
			
		||||
		m[attr] = append(m[attr], value...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return m, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LSetxattr sets all of the extended attributes on file at path, not
 | 
			
		||||
// following any symbolic links. All attributes on the target are
 | 
			
		||||
// replaced by the values from attr. If the operation fails to set any
 | 
			
		||||
// attribute, those already applied will not be rolled back.
 | 
			
		||||
func (d *driver) LSetxattr(path string, attrMap map[string][]byte) error {
 | 
			
		||||
	for attr, value := range attrMap {
 | 
			
		||||
		if err := sysx.LSetxattr(path, attr, value, 0); err != nil {
 | 
			
		||||
			return fmt.Errorf("error setting xattr %q on %s: %v", attr, path, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) DeviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error) {
 | 
			
		||||
	return devices.DeviceInfo(fi)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Readlink was forked on Windows to fix a Golang bug, use the "os" package here
 | 
			
		||||
func (d *driver) Readlink(p string) (string, error) {
 | 
			
		||||
	return os.Readlink(p)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										43
									
								
								vendor/github.com/containerd/continuity/driver/driver_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								vendor/github.com/containerd/continuity/driver/driver_windows.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/containerd/continuity/sysx"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
 | 
			
		||||
	return &os.PathError{Op: "mknod", Path: path, Err: ErrNotSupported}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *driver) Mkfifo(path string, mode os.FileMode) error {
 | 
			
		||||
	return &os.PathError{Op: "mkfifo", Path: path, Err: ErrNotSupported}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Lchmod changes the mode of an file not following symlinks.
 | 
			
		||||
func (d *driver) Lchmod(path string, mode os.FileMode) (err error) {
 | 
			
		||||
	// TODO: Use Window's equivalent
 | 
			
		||||
	return os.Chmod(path, mode)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Readlink is forked in order to support Volume paths which are used
 | 
			
		||||
// in container layers.
 | 
			
		||||
func (d *driver) Readlink(p string) (string, error) {
 | 
			
		||||
	return sysx.Readlink(p)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								vendor/github.com/containerd/continuity/driver/lchmod_linux.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								vendor/github.com/containerd/continuity/driver/lchmod_linux.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Lchmod changes the mode of a file not following symlinks.
 | 
			
		||||
func (d *driver) Lchmod(path string, mode os.FileMode) error {
 | 
			
		||||
	// On Linux, file mode is not supported for symlinks,
 | 
			
		||||
	// and fchmodat() does not support AT_SYMLINK_NOFOLLOW,
 | 
			
		||||
	// so symlinks need to be skipped entirely.
 | 
			
		||||
	if st, err := os.Stat(path); err == nil && st.Mode()&os.ModeSymlink != 0 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err := unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), 0)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		err = &os.PathError{Op: "lchmod", Path: path, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								vendor/github.com/containerd/continuity/driver/lchmod_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								vendor/github.com/containerd/continuity/driver/lchmod_unix.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
// +build darwin freebsd solaris
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sys/unix"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Lchmod changes the mode of a file not following symlinks.
 | 
			
		||||
func (d *driver) Lchmod(path string, mode os.FileMode) error {
 | 
			
		||||
	err := unix.Fchmodat(unix.AT_FDCWD, path, uint32(mode), unix.AT_SYMLINK_NOFOLLOW)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		err = &os.PathError{Op: "lchmod", Path: path, Err: err}
 | 
			
		||||
	}
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										90
									
								
								vendor/github.com/containerd/continuity/driver/utils.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								vendor/github.com/containerd/continuity/driver/utils.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
/*
 | 
			
		||||
   Copyright The containerd Authors.
 | 
			
		||||
 | 
			
		||||
   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 driver
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sort"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ReadFile works the same as ioutil.ReadFile with the Driver abstraction
 | 
			
		||||
func ReadFile(r Driver, filename string) ([]byte, error) {
 | 
			
		||||
	f, err := r.Open(filename)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	defer f.Close()
 | 
			
		||||
 | 
			
		||||
	data, err := ioutil.ReadAll(f)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return data, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WriteFile works the same as ioutil.WriteFile with the Driver abstraction
 | 
			
		||||
func WriteFile(r Driver, filename string, data []byte, perm os.FileMode) error {
 | 
			
		||||
	f, err := r.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer f.Close()
 | 
			
		||||
 | 
			
		||||
	n, err := f.Write(data)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	} else if n != len(data) {
 | 
			
		||||
		return io.ErrShortWrite
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReadDir works the same as ioutil.ReadDir with the Driver abstraction
 | 
			
		||||
func ReadDir(r Driver, dirname string) ([]os.FileInfo, error) {
 | 
			
		||||
	f, err := r.Open(dirname)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	defer f.Close()
 | 
			
		||||
 | 
			
		||||
	dirs, err := f.Readdir(-1)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sort.Sort(fileInfos(dirs))
 | 
			
		||||
	return dirs, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Simple implementation of the sort.Interface for os.FileInfo
 | 
			
		||||
type fileInfos []os.FileInfo
 | 
			
		||||
 | 
			
		||||
func (fis fileInfos) Len() int {
 | 
			
		||||
	return len(fis)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (fis fileInfos) Less(i, j int) bool {
 | 
			
		||||
	return fis[i].Name() < fis[j].Name()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (fis fileInfos) Swap(i, j int) {
 | 
			
		||||
	fis[i], fis[j] = fis[j], fis[i]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user