Skip to content

Commit

Permalink
Merge pull request #6 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.3
  • Loading branch information
andyone committed Dec 24, 2015
2 parents 44ed708 + 93f366a commit 9c425d5
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 2 additions & 8 deletions fmtutil/fmtutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ package fmtutil
// ////////////////////////////////////////////////////////////////////////////////// //

import (
. "gopkg.in/check.v1"
"testing"

. "gopkg.in/check.v1"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -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)
}
23 changes: 23 additions & 0 deletions fmtutil/termsize_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build linux

package fmtutil

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

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)
}
21 changes: 0 additions & 21 deletions system/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 61 additions & 0 deletions system/user_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ package system

import (
"errors"
"fmt"
"os/exec"
"strconv"
"strings"
"syscall"
"time"
)
Expand All @@ -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
}
25 changes: 25 additions & 0 deletions system/user_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ package system

import (
"errors"
"fmt"
"os/exec"
"strconv"
"strings"
"syscall"
"time"
)
Expand All @@ -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
}

0 comments on commit 9c425d5

Please sign in to comment.