From ee6542acd52f41233baee36ee0ab7d246226f12e Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 13 Jan 2016 11:32:56 +0100 Subject: [PATCH] Added FreeBSD support for fsutil and system packages + minor fixes in log package tests --- changelog.md | 6 ++++ log/log_test.go | 2 +- system/info_posix.go | 2 +- system/user_darwin.go | 2 +- system/user_freebsd.go | 63 ++++++++++++++++++++++++++++++++++++++++++ system/user_linux.go | 2 +- system/user_windows.go | 2 +- 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 system/user_freebsd.go diff --git a/changelog.md b/changelog.md index 00ec1fd0..254f8ddc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ ## Changelog +#### v1.4.1 + +* `[fsutil]` Added FreeBSD support +* `[system]` Added FreeBSD support +* `[log]` Some minor fixes in tests + #### v1.4.0 * `[kv]` Added package with simple key-value structs diff --git a/log/log_test.go b/log/log_test.go index ebf85088..e040e296 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -333,7 +333,7 @@ func (ls *LogSuite) TestBufIODaemon(c *C) { c.Assert(fsutil.GetSize(logfile), Equals, int64(0)) - time.Sleep(500 * time.Millisecond) + time.Sleep(2 * time.Second) c.Assert(fsutil.GetSize(logfile), Not(Equals), int64(0)) diff --git a/system/info_posix.go b/system/info_posix.go index 4f2c4c0c..d7218f3c 100644 --- a/system/info_posix.go +++ b/system/info_posix.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux, freebsd package system diff --git a/system/user_darwin.go b/system/user_darwin.go index dfff046b..ebd98757 100644 --- a/system/user_darwin.go +++ b/system/user_darwin.go @@ -1,4 +1,4 @@ -// +build darwin, !linux, !windows +// +build darwin package system diff --git a/system/user_freebsd.go b/system/user_freebsd.go new file mode 100644 index 00000000..c52beffa --- /dev/null +++ b/system/user_freebsd.go @@ -0,0 +1,63 @@ +// +build freebsd + +package system + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "errors" + "fmt" + "os/exec" + "strconv" + "strings" + "syscall" + "time" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +// getTimes is copy of fsutil.GetTimes +func getTimes(path string) (time.Time, time.Time, time.Time, error) { + if path == "" { + return time.Time{}, time.Time{}, time.Time{}, errors.New("Path is empty") + } + + var stat = &syscall.Stat_t{} + + err := syscall.Stat(path, stat) + + if err != nil { + return time.Time{}, time.Time{}, time.Time{}, err + } + + return time.Unix(int64(stat.Atimespec.Sec), int64(stat.Atimespec.Nsec)), + time.Unix(int64(stat.Mtimespec.Sec), int64(stat.Mtimespec.Nsec)), + time.Unix(int64(stat.Ctimespec.Sec), int64(stat.Ctimespec.Nsec)), + nil +} + +// getUserInfo return user info by name or id (name, id, gid, comment, home, shell) +// +func getUserInfo(nameOrID string) (string, int, int, string, string, string, error) { + cmd := exec.Command("getent", "passwd", nameOrID) + + out, err := cmd.Output() + + if err != nil { + return "", -1, -1, "", "", "", fmt.Errorf("User with this name/id %s is not exist", nameOrID) + } + + sOut := string(out[:]) + sOut = strings.Trim(sOut, "\n") + aOut := strings.Split(sOut, ":") + + uid, _ := strconv.Atoi(aOut[2]) + gid, _ := strconv.Atoi(aOut[3]) + + return aOut[0], uid, gid, aOut[4], aOut[5], aOut[6], nil +} diff --git a/system/user_linux.go b/system/user_linux.go index 573a889c..b8563fd3 100644 --- a/system/user_linux.go +++ b/system/user_linux.go @@ -1,4 +1,4 @@ -// +build linux, !darwin, !windows +// +build linux package system diff --git a/system/user_windows.go b/system/user_windows.go index 2e5df415..c804324e 100644 --- a/system/user_windows.go +++ b/system/user_windows.go @@ -1,4 +1,4 @@ -// +build !linux, !darwin, windows +// +build windows package system