diff --git a/.travis.yml b/.travis.yml index 135cc976..aabea24e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ sudo: false os: - linux - osx + - freebsd env: - EK_TEST_PORT=8080 diff --git a/changelog.md b/changelog.md index 00ec1fd0..0b9f7602 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ ## Changelog +#### v1.4.1 + +* `[fsutil]` Added partial FreeBSD support +* `[system]` Added partial FreeBSD support +* `[log]` Some minor fixes in tests + #### v1.4.0 * `[kv]` Added package with simple key-value structs diff --git a/fsutil/fs_time_darwin.go b/fsutil/fs_time_darwin.go index 7b6f3989..935348c1 100644 --- a/fsutil/fs_time_darwin.go +++ b/fsutil/fs_time_darwin.go @@ -1,4 +1,4 @@ -// +build darwin, !linux, !windows +// +build darwin package fsutil diff --git a/fsutil/fs_time_freebsd.go b/fsutil/fs_time_freebsd.go new file mode 100644 index 00000000..70b08176 --- /dev/null +++ b/fsutil/fs_time_freebsd.go @@ -0,0 +1,58 @@ +// +build freebsd + +package fsutil + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "errors" + "syscall" + "time" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +// GetTimes return time of access, modification and creation at once +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 +} + +// GetTimestamps return time of access, modification and creation at once as linux timestamp +func GetTimestamps(path string) (int64, int64, int64, error) { + if path == "" { + return -1, -1, -1, errors.New("Path is empty") + } + + var stat = &syscall.Stat_t{} + + err := syscall.Stat(path, stat) + + if err != nil { + return -1, -1, -1, err + } + + return int64(stat.Atimespec.Sec), + int64(stat.Mtimespec.Sec), + int64(stat.Ctimespec.Sec), + nil +} diff --git a/fsutil/fs_time_linux.go b/fsutil/fs_time_linux.go index e13ef113..252f575d 100644 --- a/fsutil/fs_time_linux.go +++ b/fsutil/fs_time_linux.go @@ -1,4 +1,4 @@ -// +build linux, !darwin, !windows +// +build linux package fsutil diff --git a/fsutil/fs_windows.go b/fsutil/fs_windows.go index 826d4adc..6a44bc50 100644 --- a/fsutil/fs_windows.go +++ b/fsutil/fs_windows.go @@ -1,4 +1,4 @@ -// +build windows, !linux, !darwin +// +build windows package fsutil 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.go b/system/info.go index d1db7af2..3dfe8297 100644 --- a/system/info.go +++ b/system/info.go @@ -305,7 +305,7 @@ func GetFSInfo() (map[string]*FSInfo, error) { } fsInfo.Total = stats.Blocks * uint64(stats.Bsize) - fsInfo.Free = stats.Bavail * uint64(stats.Bsize) + fsInfo.Free = uint64(stats.Bavail) * uint64(stats.Bsize) fsInfo.Used = fsInfo.Total - (stats.Bfree * uint64(stats.Bsize)) fsInfo.IOStats = ios[strings.Replace(fsInfo.Device, "/dev/", "", 1)] diff --git a/system/info_posix.go b/system/info_linux.go similarity index 100% rename from system/info_posix.go rename to system/info_linux.go 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