ソースを参照

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>
Ahmet Alp Balkan 10 年 前
コミット
3d2fae353f

+ 1 - 1
pkg/archive/archive.go

@@ -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
 		}
 		}
 
 

+ 11 - 1
pkg/archive/changes.go

@@ -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")
 
 

+ 0 - 7
pkg/archive/diff.go

@@ -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 - 0
pkg/system/lstat.go

@@ -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 - 0
pkg/system/lstat_windows.go

@@ -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 - 0
pkg/system/mknod.go

@@ -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 - 0
pkg/system/mknod_windows.go

@@ -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 - 0
pkg/system/umask.go

@@ -0,0 +1,11 @@
+// +build !windows
+
+package system
+
+import (
+	"syscall"
+)
+
+func Umask(newmask int) (oldmask int, err error) {
+	return syscall.Umask(newmask), nil
+}

+ 8 - 0
pkg/system/umask_windows.go

@@ -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
+}