Skip to content

Commit

Permalink
Merge pull request moby#4878 from kzys/freebsd-utimes
Browse files Browse the repository at this point in the history
Support FreeBSD on pkg/system/utimes_*.go
  • Loading branch information
creack committed Apr 14, 2014
2 parents 413190e + 1c90a4d commit f98ed28
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
12 changes: 11 additions & 1 deletion hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ LDFLAGS_STATIC_DOCKER="
-extldflags \"$EXTLDFLAGS_STATIC_DOCKER\"
"

if [ "$(uname -s)" = 'FreeBSD' ]; then
# Tell cgo the compiler is Clang, not GCC
# https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752
export CC=clang

# "-extld clang" is a workaround for
# https://code.google.com/p/go/issues/detail?id=6845
LDFLAGS="$LDFLAGS -extld clang"
fi

HAVE_GO_TEST_COVER=
if \
go help testflag | grep -- -cover > /dev/null \
Expand Down Expand Up @@ -142,7 +152,7 @@ go_test_dir() {
# holding certain files ($1 parameter), and prints their paths on standard
# output, one per line.
find_dirs() {
find -not \( \
find . -not \( \
\( \
-wholename './vendor' \
-o -wholename './integration' \
Expand Down
24 changes: 24 additions & 0 deletions pkg/system/utimes_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package system

import (
"syscall"
"unsafe"
)

func LUtimesNano(path string, ts []syscall.Timespec) error {
var _path *byte
_path, err := syscall.BytePtrFromString(path)
if err != nil {
return err
}

if _, _, err := syscall.Syscall(syscall.SYS_LUTIMES, uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), 0); err != 0 && err != syscall.ENOSYS {
return err
}

return nil
}

func UtimesNano(path string, ts []syscall.Timespec) error {
return syscall.UtimesNano(path, ts)
}
64 changes: 64 additions & 0 deletions pkg/system/utimes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package system

import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
)

func prepareFiles(t *testing.T) (string, string, string) {
dir, err := ioutil.TempDir("", "docker-system-test")
if err != nil {
t.Fatal(err)
}

file := filepath.Join(dir, "exist")
if err := ioutil.WriteFile(file, []byte("hello"), 0644); err != nil {
t.Fatal(err)
}

invalid := filepath.Join(dir, "doesnt-exist")

symlink := filepath.Join(dir, "symlink")
if err := os.Symlink(file, symlink); err != nil {
t.Fatal(err)
}

return file, invalid, symlink
}

func TestLUtimesNano(t *testing.T) {
file, invalid, symlink := prepareFiles(t)

before, err := os.Stat(file)
if err != nil {
t.Fatal(err)
}

ts := []syscall.Timespec{{0, 0}, {0, 0}}
if err := LUtimesNano(symlink, ts); err != nil {
t.Fatal(err)
}

symlinkInfo, err := os.Lstat(symlink)
if err != nil {
t.Fatal(err)
}
if before.ModTime().Unix() == symlinkInfo.ModTime().Unix() {
t.Fatal("The modification time of the symlink should be different")
}

fileInfo, err := os.Stat(file)
if err != nil {
t.Fatal(err)
}
if before.ModTime().Unix() != fileInfo.ModTime().Unix() {
t.Fatal("The modification time of the file should be same")
}

if err := LUtimesNano(invalid, ts); err == nil {
t.Fatal("Doesn't return an error on a non-existing file")
}
}
2 changes: 1 addition & 1 deletion pkg/system/utimes_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux
// +build !linux,!freebsd

package system

Expand Down

0 comments on commit f98ed28

Please sign in to comment.