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)
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"compress/gzip" |
| 7 | 7 |
"errors" |
| 8 | 8 |
"fmt" |
| 9 |
+ "github.com/dotcloud/docker/pkg/system" |
|
| 9 | 10 |
"github.com/dotcloud/docker/utils" |
| 10 | 11 |
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" |
| 11 | 12 |
"io" |
| ... | ... |
@@ -168,7 +169,7 @@ func addTarFile(path, name string, tw *tar.Writer) error {
|
| 168 | 168 |
|
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 |
- capability, _ := Lgetxattr(path, "security.capability") |
|
| 171 |
+ capability, _ := system.Lgetxattr(path, "security.capability") |
|
| 172 | 172 |
if capability != nil {
|
| 173 | 173 |
hdr.Xattrs = make(map[string]string) |
| 174 | 174 |
hdr.Xattrs["security.capability"] = string(capability) |
| ... | ... |
@@ -259,7 +260,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e |
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 | 261 |
for key, value := range hdr.Xattrs {
|
| 262 |
- if err := Lsetxattr(path, key, []byte(value), 0); err != nil {
|
|
| 262 |
+ if err := system.Lsetxattr(path, key, []byte(value), 0); err != nil {
|
|
| 263 | 263 |
return err |
| 264 | 264 |
} |
| 265 | 265 |
} |
| ... | ... |
@@ -275,11 +276,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader) e |
| 275 | 275 |
ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)}
|
| 276 | 276 |
// syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and |
| 277 | 277 |
if hdr.Typeflag != tar.TypeSymlink {
|
| 278 |
- if err := UtimesNano(path, ts); err != nil {
|
|
| 278 |
+ if err := system.UtimesNano(path, ts); err != nil {
|
|
| 279 | 279 |
return err |
| 280 | 280 |
} |
| 281 | 281 |
} else {
|
| 282 |
- if err := LUtimesNano(path, ts); err != nil {
|
|
| 282 |
+ if err := system.LUtimesNano(path, ts); err != nil {
|
|
| 283 | 283 |
return err |
| 284 | 284 |
} |
| 285 | 285 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package archive |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"fmt" |
| 6 |
+ "github.com/dotcloud/docker/pkg/system" |
|
| 6 | 7 |
"github.com/dotcloud/docker/utils" |
| 7 | 8 |
"github.com/dotcloud/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" |
| 8 | 9 |
"io" |
| ... | ... |
@@ -202,7 +203,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
|
| 202 | 202 |
oldStat.Rdev != newStat.Rdev || |
| 203 | 203 |
// Don't look at size for dirs, its not a good measure of change |
| 204 | 204 |
(oldStat.Size != newStat.Size && oldStat.Mode&syscall.S_IFDIR != syscall.S_IFDIR) || |
| 205 |
- !sameFsTimeSpec(getLastModification(oldStat), getLastModification(newStat)) || |
|
| 205 |
+ !sameFsTimeSpec(system.GetLastModification(oldStat), system.GetLastModification(newStat)) || |
|
| 206 | 206 |
bytes.Compare(oldChild.capability, newChild.capability) != 0 {
|
| 207 | 207 |
change := Change{
|
| 208 | 208 |
Path: newChild.path(), |
| ... | ... |
@@ -278,7 +279,7 @@ func collectFileInfo(sourceDir string) (*FileInfo, error) {
|
| 278 | 278 |
return err |
| 279 | 279 |
} |
| 280 | 280 |
|
| 281 |
- info.capability, _ = Lgetxattr(path, "security.capability") |
|
| 281 |
+ info.capability, _ = system.Lgetxattr(path, "security.capability") |
|
| 282 | 282 |
|
| 283 | 283 |
parent.children[info.name] = info |
| 284 | 284 |
|
| 285 | 285 |
deleted file mode 100644 |
| ... | ... |
@@ -1,92 +0,0 @@ |
| 1 |
-package archive |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "syscall" |
|
| 5 |
- "unsafe" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-func getLastAccess(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 9 |
- return stat.Atim |
|
| 10 |
-} |
|
| 11 |
- |
|
| 12 |
-func getLastModification(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 13 |
- return stat.Mtim |
|
| 14 |
-} |
|
| 15 |
- |
|
| 16 |
-func LUtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 17 |
- // These are not currently available in syscall |
|
| 18 |
- AT_FDCWD := -100 |
|
| 19 |
- AT_SYMLINK_NOFOLLOW := 0x100 |
|
| 20 |
- |
|
| 21 |
- var _path *byte |
|
| 22 |
- _path, err := syscall.BytePtrFromString(path) |
|
| 23 |
- if err != nil {
|
|
| 24 |
- return err |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- 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 {
|
|
| 28 |
- return err |
|
| 29 |
- } |
|
| 30 |
- |
|
| 31 |
- return nil |
|
| 32 |
-} |
|
| 33 |
- |
|
| 34 |
-func UtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 35 |
- if err := syscall.UtimesNano(path, ts); err != nil {
|
|
| 36 |
- return err |
|
| 37 |
- } |
|
| 38 |
- return nil |
|
| 39 |
-} |
|
| 40 |
- |
|
| 41 |
-// Returns a nil slice and nil error if the xattr is not set |
|
| 42 |
-func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
| 43 |
- pathBytes, err := syscall.BytePtrFromString(path) |
|
| 44 |
- if err != nil {
|
|
| 45 |
- return nil, err |
|
| 46 |
- } |
|
| 47 |
- attrBytes, err := syscall.BytePtrFromString(attr) |
|
| 48 |
- if err != nil {
|
|
| 49 |
- return nil, err |
|
| 50 |
- } |
|
| 51 |
- |
|
| 52 |
- dest := make([]byte, 128) |
|
| 53 |
- destBytes := unsafe.Pointer(&dest[0]) |
|
| 54 |
- sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 55 |
- if errno == syscall.ENODATA {
|
|
| 56 |
- return nil, nil |
|
| 57 |
- } |
|
| 58 |
- if errno == syscall.ERANGE {
|
|
| 59 |
- dest = make([]byte, sz) |
|
| 60 |
- destBytes := unsafe.Pointer(&dest[0]) |
|
| 61 |
- sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 62 |
- } |
|
| 63 |
- if errno != 0 {
|
|
| 64 |
- return nil, errno |
|
| 65 |
- } |
|
| 66 |
- |
|
| 67 |
- return dest[:sz], nil |
|
| 68 |
-} |
|
| 69 |
- |
|
| 70 |
-var _zero uintptr |
|
| 71 |
- |
|
| 72 |
-func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
| 73 |
- pathBytes, err := syscall.BytePtrFromString(path) |
|
| 74 |
- if err != nil {
|
|
| 75 |
- return err |
|
| 76 |
- } |
|
| 77 |
- attrBytes, err := syscall.BytePtrFromString(attr) |
|
| 78 |
- if err != nil {
|
|
| 79 |
- return err |
|
| 80 |
- } |
|
| 81 |
- var dataBytes unsafe.Pointer |
|
| 82 |
- if len(data) > 0 {
|
|
| 83 |
- dataBytes = unsafe.Pointer(&data[0]) |
|
| 84 |
- } else {
|
|
| 85 |
- dataBytes = unsafe.Pointer(&_zero) |
|
| 86 |
- } |
|
| 87 |
- _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) |
|
| 88 |
- if errno != 0 {
|
|
| 89 |
- return errno |
|
| 90 |
- } |
|
| 91 |
- return nil |
|
| 92 |
-} |
| 93 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,29 +0,0 @@ |
| 1 |
-// +build !linux |
|
| 2 |
- |
|
| 3 |
-package archive |
|
| 4 |
- |
|
| 5 |
-import "syscall" |
|
| 6 |
- |
|
| 7 |
-func getLastAccess(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 8 |
- return stat.Atimespec |
|
| 9 |
-} |
|
| 10 |
- |
|
| 11 |
-func getLastModification(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 12 |
- return stat.Mtimespec |
|
| 13 |
-} |
|
| 14 |
- |
|
| 15 |
-func LUtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 16 |
- return ErrNotImplemented |
|
| 17 |
-} |
|
| 18 |
- |
|
| 19 |
-func UtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 20 |
- return ErrNotImplemented |
|
| 21 |
-} |
|
| 22 |
- |
|
| 23 |
-func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
| 24 |
- return nil, ErrNotImplemented |
|
| 25 |
-} |
|
| 26 |
- |
|
| 27 |
-func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
| 28 |
- return ErrNotImplemented |
|
| 29 |
-} |
| 0 | 13 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 0 |
+// +build !linux |
|
| 1 |
+ |
|
| 2 |
+package system |
|
| 3 |
+ |
|
| 4 |
+import "syscall" |
|
| 5 |
+ |
|
| 6 |
+func GetLastAccess(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 7 |
+ return stat.Atimespec |
|
| 8 |
+} |
|
| 9 |
+ |
|
| 10 |
+func GetLastModification(stat *syscall.Stat_t) syscall.Timespec {
|
|
| 11 |
+ return stat.Mtimespec |
|
| 12 |
+} |
| 0 | 13 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,31 @@ |
| 0 |
+package system |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "syscall" |
|
| 4 |
+ "unsafe" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+func LUtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 8 |
+ // These are not currently available in syscall |
|
| 9 |
+ AT_FDCWD := -100 |
|
| 10 |
+ AT_SYMLINK_NOFOLLOW := 0x100 |
|
| 11 |
+ |
|
| 12 |
+ var _path *byte |
|
| 13 |
+ _path, err := syscall.BytePtrFromString(path) |
|
| 14 |
+ if err != nil {
|
|
| 15 |
+ return err |
|
| 16 |
+ } |
|
| 17 |
+ |
|
| 18 |
+ 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 {
|
|
| 19 |
+ return err |
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ return nil |
|
| 23 |
+} |
|
| 24 |
+ |
|
| 25 |
+func UtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 26 |
+ if err := syscall.UtimesNano(path, ts); err != nil {
|
|
| 27 |
+ return err |
|
| 28 |
+ } |
|
| 29 |
+ return nil |
|
| 30 |
+} |
| 0 | 31 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 0 |
+// +build !linux |
|
| 1 |
+ |
|
| 2 |
+package system |
|
| 3 |
+ |
|
| 4 |
+import "syscall" |
|
| 5 |
+ |
|
| 6 |
+func LUtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 7 |
+ return ErrNotSupportedPlatform |
|
| 8 |
+} |
|
| 9 |
+ |
|
| 10 |
+func UtimesNano(path string, ts []syscall.Timespec) error {
|
|
| 11 |
+ return ErrNotSupportedPlatform |
|
| 12 |
+} |
| 0 | 13 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,59 @@ |
| 0 |
+package system |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "syscall" |
|
| 4 |
+ "unsafe" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+// Returns a nil slice and nil error if the xattr is not set |
|
| 8 |
+func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
| 9 |
+ pathBytes, err := syscall.BytePtrFromString(path) |
|
| 10 |
+ if err != nil {
|
|
| 11 |
+ return nil, err |
|
| 12 |
+ } |
|
| 13 |
+ attrBytes, err := syscall.BytePtrFromString(attr) |
|
| 14 |
+ if err != nil {
|
|
| 15 |
+ return nil, err |
|
| 16 |
+ } |
|
| 17 |
+ |
|
| 18 |
+ dest := make([]byte, 128) |
|
| 19 |
+ destBytes := unsafe.Pointer(&dest[0]) |
|
| 20 |
+ sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 21 |
+ if errno == syscall.ENODATA {
|
|
| 22 |
+ return nil, nil |
|
| 23 |
+ } |
|
| 24 |
+ if errno == syscall.ERANGE {
|
|
| 25 |
+ dest = make([]byte, sz) |
|
| 26 |
+ destBytes := unsafe.Pointer(&dest[0]) |
|
| 27 |
+ sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) |
|
| 28 |
+ } |
|
| 29 |
+ if errno != 0 {
|
|
| 30 |
+ return nil, errno |
|
| 31 |
+ } |
|
| 32 |
+ |
|
| 33 |
+ return dest[:sz], nil |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+var _zero uintptr |
|
| 37 |
+ |
|
| 38 |
+func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
| 39 |
+ pathBytes, err := syscall.BytePtrFromString(path) |
|
| 40 |
+ if err != nil {
|
|
| 41 |
+ return err |
|
| 42 |
+ } |
|
| 43 |
+ attrBytes, err := syscall.BytePtrFromString(attr) |
|
| 44 |
+ if err != nil {
|
|
| 45 |
+ return err |
|
| 46 |
+ } |
|
| 47 |
+ var dataBytes unsafe.Pointer |
|
| 48 |
+ if len(data) > 0 {
|
|
| 49 |
+ dataBytes = unsafe.Pointer(&data[0]) |
|
| 50 |
+ } else {
|
|
| 51 |
+ dataBytes = unsafe.Pointer(&_zero) |
|
| 52 |
+ } |
|
| 53 |
+ _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) |
|
| 54 |
+ if errno != 0 {
|
|
| 55 |
+ return errno |
|
| 56 |
+ } |
|
| 57 |
+ return nil |
|
| 58 |
+} |
| 0 | 59 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,11 @@ |
| 0 |
+// +build !linux |
|
| 1 |
+ |
|
| 2 |
+package system |
|
| 3 |
+ |
|
| 4 |
+func Lgetxattr(path string, attr string) ([]byte, error) {
|
|
| 5 |
+ return nil, ErrNotSupportedPlatform |
|
| 6 |
+} |
|
| 7 |
+ |
|
| 8 |
+func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
|
| 9 |
+ return ErrNotSupportedPlatform |
|
| 10 |
+} |