Skip to content

Commit

Permalink
Merge pull request #41 from isimluk/published-vs-updated
Browse files Browse the repository at this point in the history
Use file system's ctime (creation time) as rolie:entry/atom:published…
  • Loading branch information
Carlos Matos committed Oct 14, 2020
2 parents a42e807 + ebe514a commit 8810a53
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/rolie/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -90,6 +91,7 @@ type scapFile struct {
AbsPath string
*scap_document.Document
Size int64
CreationTime time.Time
ModifiedTime time.Time
}

Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/utils/fs_darwin.go
Original file line number Diff line number Diff line change
@@ -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))
}
16 changes: 16 additions & 0 deletions pkg/utils/fs_linux.go
Original file line number Diff line number Diff line change
@@ -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))
}
11 changes: 11 additions & 0 deletions pkg/utils/fs_windows.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 8810a53

Please sign in to comment.