Просмотр исходного кода

Create pkg/system and move stuff there from archive

This is a package for generic system calls etc that for some reason
is not yet supported by "syscall", or where it is different enough
for the different ports to need portability wrappers.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
Alexander Larsson 11 лет назад
Родитель
Сommit
d6114c0da0

+ 5 - 4
archive/archive.go

@@ -6,6 +6,7 @@ import (
 	"compress/gzip"
 	"compress/gzip"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
+	"github.com/dotcloud/docker/pkg/system"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 	"io"
 	"io"
@@ -168,7 +169,7 @@ func addTarFile(path, name string, tw *tar.Writer) error {
 
 
 	}
 	}
 
 
-	capability, _ := Lgetxattr(path, "security.capability")
+	capability, _ := system.Lgetxattr(path, "security.capability")
 	if capability != nil {
 	if capability != nil {
 		hdr.Xattrs = make(map[string]string)
 		hdr.Xattrs = make(map[string]string)
 		hdr.Xattrs["security.capability"] = string(capability)
 		hdr.Xattrs["security.capability"] = string(capability)
@@ -259,7 +260,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e
 	}
 	}
 
 
 	for key, value := range hdr.Xattrs {
 	for key, value := range hdr.Xattrs {
-		if err := Lsetxattr(path, key, []byte(value), 0); err != nil {
+		if err := system.Lsetxattr(path, key, []byte(value), 0); err != nil {
 			return err
 			return err
 		}
 		}
 	}
 	}
@@ -275,11 +276,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e
 	ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
 	ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
 	// syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and
 	// syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and
 	if hdr.Typeflag != tar.TypeSymlink {
 	if hdr.Typeflag != tar.TypeSymlink {
-		if err := UtimesNano(path, ts); err != nil {
+		if err := system.UtimesNano(path, ts); err != nil {
 			return err
 			return err
 		}
 		}
 	} else {
 	} else {
-		if err := LUtimesNano(path, ts); err != nil {
+		if err := system.LUtimesNano(path, ts); err != nil {
 			return err
 			return err
 		}
 		}
 	}
 	}

+ 3 - 2
archive/changes.go

@@ -3,6 +3,7 @@ package archive
 import (
 import (
 	"bytes"
 	"bytes"
 	"fmt"
 	"fmt"
+	"github.com/dotcloud/docker/pkg/system"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 	"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 	"io"
 	"io"
@@ -202,7 +203,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
 				oldStat.Rdev != newStat.Rdev ||
 				oldStat.Rdev != newStat.Rdev ||
 				// Don't look at size for dirs, its not a good measure of change
 				// Don't look at size for dirs, its not a good measure of change
 				(oldStat.Size != newStat.Size && oldStat.Mode&syscall.S_IFDIR != syscall.S_IFDIR) ||
 				(oldStat.Size != newStat.Size && oldStat.Mode&syscall.S_IFDIR != syscall.S_IFDIR) ||
-				!sameFsTimeSpec(getLastModification(oldStat), getLastModification(newStat)) ||
+				!sameFsTimeSpec(system.GetLastModification(oldStat), system.GetLastModification(newStat)) ||
 				bytes.Compare(oldChild.capability, newChild.capability) != 0 {
 				bytes.Compare(oldChild.capability, newChild.capability) != 0 {
 				change := Change{
 				change := Change{
 					Path: newChild.path(),
 					Path: newChild.path(),
@@ -278,7 +279,7 @@ func collectFileInfo(sourceDir string) (*FileInfo, error) {
 			return err
 			return err
 		}
 		}
 
 
-		info.capability, _ = Lgetxattr(path, "security.capability")
+		info.capability, _ = system.Lgetxattr(path, "security.capability")
 
 
 		parent.children[info.name] = info
 		parent.children[info.name] = info
 
 

+ 0 - 29
archive/stat_unsupported.go

@@ -1,29 +0,0 @@
-// +build !linux
-
-package archive
-
-import "syscall"
-
-func getLastAccess(stat *syscall.Stat_t) syscall.Timespec {
-	return stat.Atimespec
-}
-
-func getLastModification(stat *syscall.Stat_t) syscall.Timespec {
-	return stat.Mtimespec
-}
-
-func LUtimesNano(path string, ts []syscall.Timespec) error {
-	return ErrNotImplemented
-}
-
-func UtimesNano(path string, ts []syscall.Timespec) error {
-	return ErrNotImplemented
-}
-
-func Lgetxattr(path string, attr string) ([]byte, error) {
-	return nil, ErrNotImplemented
-}
-
-func Lsetxattr(path string, attr string, data []byte, flags int) error {
-	return ErrNotImplemented
-}

+ 13 - 0
pkg/system/stat_linux.go

@@ -0,0 +1,13 @@
+package system
+
+import (
+	"syscall"
+)
+
+func GetLastAccess(stat *syscall.Stat_t) syscall.Timespec {
+	return stat.Atim
+}
+
+func GetLastModification(stat *syscall.Stat_t) syscall.Timespec {
+	return stat.Mtim
+}

+ 13 - 0
pkg/system/stat_unsupported.go

@@ -0,0 +1,13 @@
+// +build !linux
+
+package system
+
+import "syscall"
+
+func GetLastAccess(stat *syscall.Stat_t) syscall.Timespec {
+	return stat.Atimespec
+}
+
+func GetLastModification(stat *syscall.Stat_t) syscall.Timespec {
+	return stat.Mtimespec
+}

+ 31 - 0
pkg/system/utimes_linux.go

@@ -0,0 +1,31 @@
+package system
+
+import (
+	"syscall"
+	"unsafe"
+)
+
+func LUtimesNano(path string, ts []syscall.Timespec) error {
+	// These are not currently available in syscall
+	AT_FDCWD := -100
+	AT_SYMLINK_NOFOLLOW := 0x100
+
+	var _path *byte
+	_path, err := syscall.BytePtrFromString(path)
+	if err != nil {
+		return err
+	}
+
+	if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(AT_FDCWD), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(AT_SYMLINK_NOFOLLOW), 0, 0); err != 0 && err != syscall.ENOSYS {
+		return err
+	}
+
+	return nil
+}
+
+func UtimesNano(path string, ts []syscall.Timespec) error {
+	if err := syscall.UtimesNano(path, ts); err != nil {
+		return err
+	}
+	return nil
+}

+ 13 - 0
pkg/system/utimes_unsupported.go

@@ -0,0 +1,13 @@
+// +build !linux
+
+package system
+
+import "syscall"
+
+func LUtimesNano(path string, ts []syscall.Timespec) error {
+	return ErrNotSupportedPlatform
+}
+
+func UtimesNano(path string, ts []syscall.Timespec) error {
+	return ErrNotSupportedPlatform
+}

+ 1 - 34
archive/stat_linux.go → pkg/system/xattrs_linux.go

@@ -1,43 +1,10 @@
-package archive
+package system
 
 
 import (
 import (
 	"syscall"
 	"syscall"
 	"unsafe"
 	"unsafe"
 )
 )
 
 
-func getLastAccess(stat *syscall.Stat_t) syscall.Timespec {
-	return stat.Atim
-}
-
-func getLastModification(stat *syscall.Stat_t) syscall.Timespec {
-	return stat.Mtim
-}
-
-func LUtimesNano(path string, ts []syscall.Timespec) error {
-	// These are not currently available in syscall
-	AT_FDCWD := -100
-	AT_SYMLINK_NOFOLLOW := 0x100
-
-	var _path *byte
-	_path, err := syscall.BytePtrFromString(path)
-	if err != nil {
-		return err
-	}
-
-	if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(AT_FDCWD), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(AT_SYMLINK_NOFOLLOW), 0, 0); err != 0 && err != syscall.ENOSYS {
-		return err
-	}
-
-	return nil
-}
-
-func UtimesNano(path string, ts []syscall.Timespec) error {
-	if err := syscall.UtimesNano(path, ts); err != nil {
-		return err
-	}
-	return nil
-}
-
 // Returns a nil slice and nil error if the xattr is not set
 // Returns a nil slice and nil error if the xattr is not set
 func Lgetxattr(path string, attr string) ([]byte, error) {
 func Lgetxattr(path string, attr string) ([]byte, error) {
 	pathBytes, err := syscall.BytePtrFromString(path)
 	pathBytes, err := syscall.BytePtrFromString(path)

+ 11 - 0
pkg/system/xattrs_unsupported.go

@@ -0,0 +1,11 @@
+// +build !linux
+
+package system
+
+func Lgetxattr(path string, attr string) ([]byte, error) {
+	return nil, ErrNotSupportedPlatform
+}
+
+func Lsetxattr(path string, attr string, data []byte, flags int) error {
+	return ErrNotSupportedPlatform
+}