diff --git a/pkg/rolie/new.go b/pkg/rolie/new.go index 081582c..4e4be4e 100644 --- a/pkg/rolie/new.go +++ b/pkg/rolie/new.go @@ -12,6 +12,7 @@ import ( "github.com/gocomply/scap/pkg/scap/scap_document" "github.com/rolieup/golie/pkg/models" "github.com/rolieup/golie/pkg/rolie_source" + "github.com/rolieup/golie/pkg/utils" log "github.com/sirupsen/logrus" ) @@ -90,6 +91,7 @@ type scapFile struct { AbsPath string *scap_document.Document Size int64 + CreationTime time.Time ModifiedTime time.Time } @@ -110,7 +112,7 @@ func (scap *scapFile) RolieEntry(baseUri string) (*models.Entry, error) { }, } entry.Updated = models.Time(scap.ModifiedTime) // when was entry modified in significant way? (see RFC 4287; 4.2.15.) - entry.Published = models.Time(time.Now()) + entry.Published = models.Time(scap.CreationTime) entry.Content = &models.Text{ Type: scap.MIMEType(), Src: scap.Link(baseUri), @@ -203,6 +205,7 @@ func traverseScapFiles(directoryPath string) (<-chan scapFile, error) { AbsPath: path, Document: nil, // deferred Size: info.Size(), + CreationTime: utils.FileCreationTime(info), ModifiedTime: info.ModTime(), } return nil diff --git a/pkg/utils/fs_darwin.go b/pkg/utils/fs_darwin.go new file mode 100644 index 0000000..fd67a87 --- /dev/null +++ b/pkg/utils/fs_darwin.go @@ -0,0 +1,15 @@ +package utils + +import ( + "os" + "syscall" + "time" +) + +func FileCreationTime(finfo os.FileInfo) time.Time { + return timespecToTime(finfo.Sys().(*syscall.Stat_t).Ctimespec) +} + +func timespecToTime(ts syscall.Timespec) time.Time { + return time.Unix(int64(ts.Sec), int64(ts.Nsec)) +} diff --git a/pkg/utils/fs_linux.go b/pkg/utils/fs_linux.go new file mode 100644 index 0000000..92e053e --- /dev/null +++ b/pkg/utils/fs_linux.go @@ -0,0 +1,16 @@ +package utils + +import ( + "os" + "syscall" + "time" +) + +func FileCreationTime(finfo os.FileInfo) time.Time { + statT := finfo.Sys().(*syscall.Stat_t) + return timespecToTime(statT.Ctim) +} + +func timespecToTime(ts syscall.Timespec) time.Time { + return time.Unix(int64(ts.Sec), int64(ts.Nsec)) +} diff --git a/pkg/utils/fs_windows.go b/pkg/utils/fs_windows.go new file mode 100644 index 0000000..75b9f4a --- /dev/null +++ b/pkg/utils/fs_windows.go @@ -0,0 +1,11 @@ +package utils + +import ( + "os" + "syscall" + "time" +) + +func FileCreationTime(finfo os.FileInfo) time.Time { + return time.Unix(0, finfo.Sys().(*syscall.Win32FileAttributeData).CreationTime.Nanoseconds()) +}