From ad4c814e19b46dd9d3ae4aab669ff4a836b3be65 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Wed, 13 Jan 2016 11:43:31 +0100 Subject: [PATCH] Added partial FreeBSD support for fsutil and system packages --- fsutil/fs_time_darwin.go | 2 +- fsutil/fs_time_freebsd.go | 58 +++++++++++++++++++++++++++++++++++++++ fsutil/fs_time_linux.go | 2 +- fsutil/fs_windows.go | 2 +- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 fsutil/fs_time_freebsd.go diff --git a/fsutil/fs_time_darwin.go b/fsutil/fs_time_darwin.go index 7b6f3989..935348c1 100644 --- a/fsutil/fs_time_darwin.go +++ b/fsutil/fs_time_darwin.go @@ -1,4 +1,4 @@ -// +build darwin, !linux, !windows +// +build darwin package fsutil diff --git a/fsutil/fs_time_freebsd.go b/fsutil/fs_time_freebsd.go new file mode 100644 index 00000000..70b08176 --- /dev/null +++ b/fsutil/fs_time_freebsd.go @@ -0,0 +1,58 @@ +// +build freebsd + +package fsutil + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2009-2016 Essential Kaos // +// Essential Kaos Open Source License // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +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 +} diff --git a/fsutil/fs_time_linux.go b/fsutil/fs_time_linux.go index e13ef113..252f575d 100644 --- a/fsutil/fs_time_linux.go +++ b/fsutil/fs_time_linux.go @@ -1,4 +1,4 @@ -// +build linux, !darwin, !windows +// +build linux package fsutil diff --git a/fsutil/fs_windows.go b/fsutil/fs_windows.go index 826d4adc..6a44bc50 100644 --- a/fsutil/fs_windows.go +++ b/fsutil/fs_windows.go @@ -1,4 +1,4 @@ -// +build windows, !linux, !darwin +// +build windows package fsutil