Skip to content

Commit

Permalink
scanner: use create time if we have it
Browse files Browse the repository at this point in the history
  • Loading branch information
sentriz committed May 15, 2024
1 parent f5893ea commit 6afe9f5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/fileutil"
"go.senan.xyz/gonic/scanner/ctime"
"go.senan.xyz/gonic/tags/tagcommon"
)

Expand Down Expand Up @@ -363,7 +364,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db
return fmt.Errorf("populate track artists: %w", err)
}

if err := populateAlbum(tx, album, trags, stat.ModTime()); err != nil {
if err := populateAlbum(tx, album, trags, stat.ModTime(), ctime.CreateTime(stat)); err != nil {
return fmt.Errorf("populate album: %w", err)
}

Expand Down Expand Up @@ -402,7 +403,7 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db
return nil
}

func populateAlbum(tx *db.DB, album *db.Album, trags tagcommon.Info, modTime time.Time) error {
func populateAlbum(tx *db.DB, album *db.Album, trags tagcommon.Info, modTime, createTime time.Time) error {
albumName := tagcommon.MustAlbum(trags)
album.TagTitle = albumName
album.TagTitleUDec = decoded(albumName)
Expand All @@ -411,8 +412,8 @@ func populateAlbum(tx *db.DB, album *db.Album, trags tagcommon.Info, modTime tim
album.TagYear = trags.Year()

album.ModifiedAt = modTime
if album.CreatedAt.After(modTime) {
album.CreatedAt = modTime // reset created at to match filesytem for new albums
if album.CreatedAt.After(createTime) {
album.CreatedAt = createTime // reset created at to match filesytem for new albums
}

if err := tx.Save(&album).Error; err != nil {
Expand Down

0 comments on commit 6afe9f5

Please sign in to comment.