Skip to content

Commit

Permalink
Merge pull request #13 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.4.1
  • Loading branch information
andyone committed Jan 13, 2016
2 parents 01409e7 + 9f829aa commit e7dc63c
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sudo: false
os:
- linux
- osx
- freebsd

env:
- EK_TEST_PORT=8080
Expand Down
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 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
Expand Down
2 changes: 1 addition & 1 deletion fsutil/fs_time_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin, !linux, !windows
// +build darwin

package fsutil

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

package fsutil

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

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

package fsutil

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

package fsutil

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.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
File renamed without changes.
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 e7dc63c

Please sign in to comment.