From 18bea2495d0bcc354a2538cb161081cb56e5c6f7 Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Sat, 1 Mar 2014 07:45:56 +0900 Subject: [PATCH 1/3] Use LLVM Clang explicitly on FreeBSD Docker-DCO-1.1-Signed-off-by: Kato Kazuyoshi (github: kzys) --- hack/make.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hack/make.sh b/hack/make.sh index 4db4349518..c78671ae7c 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -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 \ From 66baf56601f4fc1e8f5f2863d227283954b73a77 Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Fri, 21 Mar 2014 14:31:39 +0900 Subject: [PATCH 2/3] Unlike GNU find, FreeBSD's find needs a path before an expression Docker-DCO-1.1-Signed-off-by: Kato Kazuyoshi (github: kzys) --- hack/make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/make.sh b/hack/make.sh index c78671ae7c..f3264c9ce3 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -152,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' \ From 1c90a4dd9a83526ca3837ab9231ff6a9af07e072 Mon Sep 17 00:00:00 2001 From: Kato Kazuyoshi Date: Fri, 21 Mar 2014 00:52:00 +0900 Subject: [PATCH 3/3] Support FreeBSD on pkg/system/utimes_*.go Implement system.LUtimesNano and system.UtimesNano. The latter might be removed in future because it's basically same as os.Chtimes. That's why the test is mainly focusing LUtimesNano. Docker-DCO-1.1-Signed-off-by: Kato Kazuyoshi (github: kzys) --- pkg/system/utimes_freebsd.go | 24 ++++++++++++ pkg/system/utimes_test.go | 64 ++++++++++++++++++++++++++++++++ pkg/system/utimes_unsupported.go | 2 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 pkg/system/utimes_freebsd.go create mode 100644 pkg/system/utimes_test.go diff --git a/pkg/system/utimes_freebsd.go b/pkg/system/utimes_freebsd.go new file mode 100644 index 0000000000..ceaa044c1c --- /dev/null +++ b/pkg/system/utimes_freebsd.go @@ -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) +} diff --git a/pkg/system/utimes_test.go b/pkg/system/utimes_test.go new file mode 100644 index 0000000000..38e4020cb5 --- /dev/null +++ b/pkg/system/utimes_test.go @@ -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") + } +} diff --git a/pkg/system/utimes_unsupported.go b/pkg/system/utimes_unsupported.go index d247ba283e..9a8cf9cd4a 100644 --- a/pkg/system/utimes_unsupported.go +++ b/pkg/system/utimes_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux +// +build !linux,!freebsd package system