buildah/copier/syscall_windows.go

89 lines
1.6 KiB
Go
Raw Permalink Normal View History

// +build windows
package copier
import (
copier: add Mkdir() Add a function for doing Mkdir-possibly-in-a-chroot, for ensuring that a directory exists without having to possibly create it directly from outside of a chroot. Make use of filepath.ToSlash() and filepath.FromSlash() where it's appropriate. Add more unit tests. Address some review comments: * Check for ERANGE instead of E2BIG errors from llistxattr() and lgetxattr() as indicators that the buffer we passed to them is too small. * Factor an `isRelevantXattr` helper out of Lgetxattrs() and Lsetxattrs(). * Drop our getcwd() function in favor of using os.Getwd(). * Adjust the comment describing the GetOptions.KeepDirectoryNames field. * Clean hdr.Name before attempting to compute where an item being extracted should go. * When writing items to the filesystem, create with 0?00 permissions, set ownership, then set the correct permissions. * Merge StatResponse.Error, GetResponse.Error, and PutResponse.Error into Response.Error. * When reading items from the filesystem, if a glob matches multiple items, and one of the items is excluded, continue checking the other items. * Make sure we always Wait() on a child process if we spawned one. * Clean up the cleanup logic for pipes that we use to communicate with a child process. * Clean up the kill-the-child-process logic we call when we encounter an error communicating with the child process. * Drop the separate Options structure, use helper methods to simplify pulling out the right ID maps and exclusions list for the request. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-31 02:00:25 +08:00
"errors"
"os"
"syscall"
"time"
"golang.org/x/sys/windows"
)
var canChroot = false
func chroot(path string) (bool, error) {
return false, nil
}
func chrMode(mode os.FileMode) uint32 {
return windows.S_IFCHR | uint32(mode)
}
func blkMode(mode os.FileMode) uint32 {
return windows.S_IFBLK | uint32(mode)
}
func mkdev(major, minor uint32) uint64 {
return 0
}
func mkfifo(path string, mode uint32) error {
return syscall.ENOSYS
}
func mknod(path string, mode uint32, dev int) error {
return syscall.ENOSYS
}
copier: add Mkdir() Add a function for doing Mkdir-possibly-in-a-chroot, for ensuring that a directory exists without having to possibly create it directly from outside of a chroot. Make use of filepath.ToSlash() and filepath.FromSlash() where it's appropriate. Add more unit tests. Address some review comments: * Check for ERANGE instead of E2BIG errors from llistxattr() and lgetxattr() as indicators that the buffer we passed to them is too small. * Factor an `isRelevantXattr` helper out of Lgetxattrs() and Lsetxattrs(). * Drop our getcwd() function in favor of using os.Getwd(). * Adjust the comment describing the GetOptions.KeepDirectoryNames field. * Clean hdr.Name before attempting to compute where an item being extracted should go. * When writing items to the filesystem, create with 0?00 permissions, set ownership, then set the correct permissions. * Merge StatResponse.Error, GetResponse.Error, and PutResponse.Error into Response.Error. * When reading items from the filesystem, if a glob matches multiple items, and one of the items is excluded, continue checking the other items. * Make sure we always Wait() on a child process if we spawned one. * Clean up the cleanup logic for pipes that we use to communicate with a child process. * Clean up the kill-the-child-process logic we call when we encounter an error communicating with the child process. * Drop the separate Options structure, use helper methods to simplify pulling out the right ID maps and exclusions list for the request. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-31 02:00:25 +08:00
func chmod(path string, mode os.FileMode) error {
err := os.Chmod(path, mode)
if err != nil && errors.Is(err, syscall.EWINDOWS) {
return nil
}
return err
}
func chown(path string, uid, gid int) error {
err := os.Chown(path, uid, gid)
if err != nil && errors.Is(err, syscall.EWINDOWS) {
return nil
}
return err
}
func lchown(path string, uid, gid int) error {
err := os.Lchown(path, uid, gid)
if err != nil && errors.Is(err, syscall.EWINDOWS) {
return nil
}
return err
}
func lutimes(isSymlink bool, path string, atime, mtime time.Time) error {
if isSymlink {
return nil
}
if atime.IsZero() || mtime.IsZero() {
now := time.Now()
if atime.IsZero() {
atime = now
}
if mtime.IsZero() {
mtime = now
}
}
return windows.UtimesNano(path, []windows.Timespec{windows.NsecToTimespec(atime.UnixNano()), windows.NsecToTimespec(mtime.UnixNano())})
}
copier: add Mkdir() Add a function for doing Mkdir-possibly-in-a-chroot, for ensuring that a directory exists without having to possibly create it directly from outside of a chroot. Make use of filepath.ToSlash() and filepath.FromSlash() where it's appropriate. Add more unit tests. Address some review comments: * Check for ERANGE instead of E2BIG errors from llistxattr() and lgetxattr() as indicators that the buffer we passed to them is too small. * Factor an `isRelevantXattr` helper out of Lgetxattrs() and Lsetxattrs(). * Drop our getcwd() function in favor of using os.Getwd(). * Adjust the comment describing the GetOptions.KeepDirectoryNames field. * Clean hdr.Name before attempting to compute where an item being extracted should go. * When writing items to the filesystem, create with 0?00 permissions, set ownership, then set the correct permissions. * Merge StatResponse.Error, GetResponse.Error, and PutResponse.Error into Response.Error. * When reading items from the filesystem, if a glob matches multiple items, and one of the items is excluded, continue checking the other items. * Make sure we always Wait() on a child process if we spawned one. * Clean up the cleanup logic for pipes that we use to communicate with a child process. * Clean up the kill-the-child-process logic we call when we encounter an error communicating with the child process. * Drop the separate Options structure, use helper methods to simplify pulling out the right ID maps and exclusions list for the request. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-31 02:00:25 +08:00
// sameDevice returns true since we can't be sure that they're not on the same device
func sameDevice(a, b os.FileInfo) bool {
return true
}
copier: add Mkdir() Add a function for doing Mkdir-possibly-in-a-chroot, for ensuring that a directory exists without having to possibly create it directly from outside of a chroot. Make use of filepath.ToSlash() and filepath.FromSlash() where it's appropriate. Add more unit tests. Address some review comments: * Check for ERANGE instead of E2BIG errors from llistxattr() and lgetxattr() as indicators that the buffer we passed to them is too small. * Factor an `isRelevantXattr` helper out of Lgetxattrs() and Lsetxattrs(). * Drop our getcwd() function in favor of using os.Getwd(). * Adjust the comment describing the GetOptions.KeepDirectoryNames field. * Clean hdr.Name before attempting to compute where an item being extracted should go. * When writing items to the filesystem, create with 0?00 permissions, set ownership, then set the correct permissions. * Merge StatResponse.Error, GetResponse.Error, and PutResponse.Error into Response.Error. * When reading items from the filesystem, if a glob matches multiple items, and one of the items is excluded, continue checking the other items. * Make sure we always Wait() on a child process if we spawned one. * Clean up the cleanup logic for pipes that we use to communicate with a child process. * Clean up the kill-the-child-process logic we call when we encounter an error communicating with the child process. * Drop the separate Options structure, use helper methods to simplify pulling out the right ID maps and exclusions list for the request. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2020-07-31 02:00:25 +08:00
const (
testModeMask = int64(0600)
testIgnoreSymlinkDates = true
)