Extract mknod, umask, lstat to pkg/system
Some parts of pkg/archive is called on both client/daemon code. To get it compiling on Windows, these funcs are extracted into files with build tags. Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
This commit is contained in:
parent
91ea04eea7
commit
515e7481de
9 changed files with 89 additions and 9 deletions
|
@ -291,7 +291,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
|
||||||
mode |= syscall.S_IFIFO
|
mode |= syscall.S_IFIFO
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
|
if err := syscall.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,14 @@ func newRootFileInfo() *FileInfo {
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lstat(path string) (*stat, error) {
|
||||||
|
s, err := system.Lstat(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return fromStatT(s), nil
|
||||||
|
}
|
||||||
|
|
||||||
func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
||||||
root := newRootFileInfo()
|
root := newRootFileInfo()
|
||||||
|
|
||||||
|
@ -299,9 +307,11 @@ func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.Lstat(path, &info.stat); err != nil {
|
s, err := lstat(path)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
info.stat = s
|
||||||
|
|
||||||
info.capability, _ = system.Lgetxattr(path, "security.capability")
|
info.capability, _ = system.Lgetxattr(path, "security.capability")
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/pools"
|
"github.com/docker/docker/pkg/pools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes.
|
|
||||||
// They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major,
|
|
||||||
// then the top 12 bits of the minor
|
|
||||||
func mkdev(major int64, minor int64) uint32 {
|
|
||||||
return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
// ApplyLayer parses a diff in the standard layer format from `layer`, and
|
||||||
// applies it to the directory `dest`.
|
// applies it to the directory `dest`.
|
||||||
func ApplyLayer(dest string, layer ArchiveReader) error {
|
func ApplyLayer(dest string, layer ArchiveReader) error {
|
||||||
|
|
16
system/lstat.go
Normal file
16
system/lstat.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Lstat(path string) (*syscall.Stat_t, error) {
|
||||||
|
s := &syscall.Stat_t{}
|
||||||
|
err := syscall.Lstat(path, s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
12
system/lstat_windows.go
Normal file
12
system/lstat_windows.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Lstat(path string) (*syscall.Win32FileAttributeData, error) {
|
||||||
|
// should not be called on cli code path
|
||||||
|
return nil, ErrNotSupportedPlatform
|
||||||
|
}
|
18
system/mknod.go
Normal file
18
system/mknod.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Mknod(path string, mode uint32, dev int) error {
|
||||||
|
return syscall.Mknod(path, mode, dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes.
|
||||||
|
// They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major,
|
||||||
|
// then the top 12 bits of the minor
|
||||||
|
func Mkdev(major int64, minor int64) uint32 {
|
||||||
|
return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff))
|
||||||
|
}
|
12
system/mknod_windows.go
Normal file
12
system/mknod_windows.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
func Mknod(path string, mode uint32, dev int) error {
|
||||||
|
// should not be called on cli code path
|
||||||
|
return ErrNotSupportedPlatform
|
||||||
|
}
|
||||||
|
|
||||||
|
func Mkdev(major int64, minor int64) uint32 {
|
||||||
|
panic("Mkdev not implemented on windows, should not be called on cli code")
|
||||||
|
}
|
11
system/umask.go
Normal file
11
system/umask.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Umask(newmask int) (oldmask int, err error) {
|
||||||
|
return syscall.Umask(newmask), nil
|
||||||
|
}
|
8
system/umask_windows.go
Normal file
8
system/umask_windows.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
func Umask(newmask int) (oldmask int, err error) {
|
||||||
|
// should not be called on cli code path
|
||||||
|
return 0, ErrNotSupportedPlatform
|
||||||
|
}
|
Loading…
Reference in a new issue