Skip to content

Commit

Permalink
Added FreeBSD support for fsutil and system packages + minor fixes in…
Browse files Browse the repository at this point in the history
… log package tests
  • Loading branch information
andyone committed Jan 13, 2016
1 parent d6a3434 commit ee6542a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion system/info_posix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux
// +build linux, freebsd

package system

Expand Down
2 changes: 1 addition & 1 deletion system/user_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin, !linux, !windows
// +build darwin

package system

Expand Down
63 changes: 63 additions & 0 deletions system/user_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// +build freebsd

package system

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2016 Essential Kaos //
// Essential Kaos Open Source License <http://essentialkaos.com/ekol?en> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

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
}
2 changes: 1 addition & 1 deletion system/user_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux, !darwin, !windows
// +build linux

package system

Expand Down
2 changes: 1 addition & 1 deletion system/user_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux, !darwin, windows
// +build windows

package system

Expand Down

0 comments on commit ee6542a

Please sign in to comment.