-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expanded file datetime options #182
Conversation
Add created at
thanks @b-levin this makes sense to me 👍 though now I'm wondering if the extra config option is really worth it, if we're only affecting home pages. so what if we went with something even more simple, add a safety check where if the cast to Stat_t fails (which happen on non linux systems), use an empty time.Time and let gorm's automatic CreatedAt be used instead the diff against master could be diff --git a/server/ctrladmin/handlers.go b/server/ctrladmin/handlers.go
index af25b09..10a1bc7 100644
--- a/server/ctrladmin/handlers.go
+++ b/server/ctrladmin/handlers.go
@@ -47,7 +47,7 @@ func (c *Controller) ServeHome(r *http.Request) *Response {
// recent folders box
c.DB.
Where("tag_artist_id IS NOT NULL").
- Order("modified_at DESC").
+ Order("created_at DESC").
Limit(8).
Find(&data.RecentFolders)
data.IsScanning = c.Scanner.IsScanning()
diff --git a/server/scanner/scanner.go b/server/scanner/scanner.go
index e9031fb..d102356 100644
--- a/server/scanner/scanner.go
+++ b/server/scanner/scanner.go
@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"sync/atomic"
+ "syscall"
"time"
"github.com/jinzhu/gorm"
@@ -243,8 +244,8 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *ctx, i int, album *
return nil
}
- if err := populateAlbum(tx, album, albumArtist, trags, stat.ModTime()); err != nil {
- return fmt.Errorf("propulate album: %w", err)
+ if err := populateAlbum(tx, album, albumArtist, trags, stat.ModTime(), statCreateTime(stat)); err != nil {
+ return fmt.Errorf("populate album: %w", err)
}
if err := populateAlbumGenres(tx, album, genreIDs); err != nil {
@@ -254,14 +255,18 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *ctx, i int, album *
return nil
}
-func populateAlbum(tx *db.DB, album *db.Album, albumArtist *db.Artist, trags tags.Parser, modTime time.Time) error {
+func populateAlbum(tx *db.DB, album *db.Album, albumArtist *db.Artist, trags tags.Parser, modTime time.Time, createTime time.Time) error {
albumName := trags.SomeAlbum()
album.TagTitle = albumName
album.TagTitleUDec = decoded(albumName)
album.TagBrainzID = trags.AlbumBrainzID()
album.TagYear = trags.Year()
album.TagArtistID = albumArtist.ID
+
album.ModifiedAt = modTime
+ if !createTime.IsZero() {
+ album.CreatedAt = createTime
+ }
if err := tx.Save(&album).Error; err != nil {
return fmt.Errorf("saving album: %w", err)
@@ -503,3 +508,14 @@ type ctx struct {
seenAlbums map[int]struct{}
seenTracksNew int
}
+
+func statCreateTime(info fs.FileInfo) time.Time {
+ stat, ok := info.Sys().(*syscall.Stat_t)
+ if !ok {
+ return time.Time{}
+ }
+ if stat.Ctim.Sec == 0 {
+ return time.Time{}
+ }
+ return time.Unix(stat.Ctim.Sec, stat.Ctim.Nsec)
+} without the funny formatting. would you be ok with this? see any drawbacks? cheers! |
Yeah those changes look excellent, no drawbacks either, thanks again! The extra config options could definitely be dropped to keep things simpler as well. |
closes #182 closes #135 Co-authored-by: b-levin <[email protected]>
closes #182 closes #135 Co-authored-by: b-levin <[email protected]>
closes #182 closes #135 Co-authored-by: b-levin <[email protected]>
closes #135
Expanded the date parameters stored in the Album struct to include CreatedAt (in addition to ModifiedAt). Additionally, users can now use the create-sort option in the file config or command line flag to change which date (CreatedAt or ModifiedAt) is used for the sorting in the ServeHome function.
TODO