diff --git a/.travis.yml b/.travis.yml index 71242fea..f51c2d8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,17 +2,19 @@ language: go go: - 1.4.2 - 1.5.2 - - release - tip sudo: false +os: + - linux + - osx + env: - EK_TEST_PORT=8080 before_install: - go get gopkg.in/check.v1 - - go get golang.org/x/tools/cmd/cover script: - .travis/script.sh . diff --git a/changelog.md b/changelog.md index 2ff81826..6375bea6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ ## Changelog +#### v1.3 + +* `[system]` Fixed major bug with OS X compatibility +* `[fmtutil]` Fixed tests for OS X + #### v1.2.2 * `[req]` Added flag for marking connection to close diff --git a/fmtutil/fmtutil_test.go b/fmtutil/fmtutil_test.go index 31041c3a..90287b63 100644 --- a/fmtutil/fmtutil_test.go +++ b/fmtutil/fmtutil_test.go @@ -8,8 +8,9 @@ package fmtutil // ////////////////////////////////////////////////////////////////////////////////// // import ( - . "gopkg.in/check.v1" "testing" + + . "gopkg.in/check.v1" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -132,10 +133,3 @@ func (s *FmtUtilSuite) TestSeparator(c *C) { Separator(true, "test") Separator(false, "test") } - -func (s *FmtUtilSuite) TestTermSize(c *C) { - w, h := GetTermSize() - - c.Assert(w, Not(Equals), 0) - c.Assert(h, Not(Equals), 0) -} diff --git a/fmtutil/termsize_linux_test.go b/fmtutil/termsize_linux_test.go new file mode 100644 index 00000000..9edb5071 --- /dev/null +++ b/fmtutil/termsize_linux_test.go @@ -0,0 +1,23 @@ +// +build linux + +package fmtutil + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2015 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + . "gopkg.in/check.v1" +) + +// //////////////////////////////////////////////////// + +func (s *FmtUtilSuite) TestTermSize(c *C) { + w, h := GetTermSize() + + c.Assert(w, Not(Equals), 0) + c.Assert(h, Not(Equals), 0) +} diff --git a/system/user.go b/system/user.go index d3726711..55a42344 100644 --- a/system/user.go +++ b/system/user.go @@ -292,27 +292,6 @@ func getTDOwnerID() (int, bool) { return ownerID, err == nil } -// getUserInfo return user info by name or id -// -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 -} - // getGroupInfo return group info by name or id func getGroupInfo(nameOrID string) (string, int, error) { cmd := exec.Command("getent", "group", nameOrID) diff --git a/system/user_darwin.go b/system/user_darwin.go index badec62d..84526db2 100644 --- a/system/user_darwin.go +++ b/system/user_darwin.go @@ -11,6 +11,10 @@ package system import ( "errors" + "fmt" + "os/exec" + "strconv" + "strings" "syscall" "time" ) @@ -36,3 +40,60 @@ func getTimes(path string) (time.Time, time.Time, time.Time, error) { time.Unix(int64(stat.Ctimespec.Sec), int64(stat.Ctimespec.Nsec)), nil } + +// getUserInfo return user info by name (name, id, gid, comment, home, shell) +// +func getUserInfo(nameOrID string) (string, int, int, string, string, string, error) { + cmd := exec.Command("dscl", ".", "-read", "/Users/"+nameOrID) + + out, err := cmd.Output() + + if err != nil || len(out) == 0 { + return "", -1, -1, "", "", "", fmt.Errorf("User with this name/id %s is not exist", nameOrID) + } + + var ( + lineStart = 0 + uid int + gid int + home string + shell string + ) + + for i, b := range out { + if b != '\n' { + continue + } + + // Skip long lines + if i-lineStart > 128 { + lineStart = i + 1 + continue + } + + line := string(out[lineStart:i]) + + lineStart = i + 1 + + sepIndex := strings.Index(line, ":") + + if sepIndex == -1 { + continue + } + + rec := line[0:sepIndex] + + switch rec { + case "UniqueID": + uid, _ = strconv.Atoi(line[sepIndex+2:]) + case "PrimaryGroupID": + gid, _ = strconv.Atoi(line[sepIndex+2:]) + case "NFSHomeDirectory": + home = line[sepIndex+2:] + case "UserShell": + shell = line[sepIndex+2:] + } + } + + return nameOrID, uid, gid, "", home, shell, nil +} diff --git a/system/user_linux.go b/system/user_linux.go index 8d298f39..111a76a4 100644 --- a/system/user_linux.go +++ b/system/user_linux.go @@ -11,6 +11,10 @@ package system import ( "errors" + "fmt" + "os/exec" + "strconv" + "strings" "syscall" "time" ) @@ -36,3 +40,24 @@ func getTimes(path string) (time.Time, time.Time, time.Time, error) { time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.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 +}