Skip to content

Commit

Permalink
Added partial FreeBSD support for fsutil and system packages
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jan 13, 2016
1 parent 5b91aa6 commit ad4c814
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
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

0 comments on commit ad4c814

Please sign in to comment.