mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-02 12:07:37 +03:00
feat(scanner): use ctime for scans, if the FS supports it
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
3394580413
commit
bc13408c6c
2 changed files with 33 additions and 7 deletions
|
@ -66,7 +66,7 @@ func (lfs *localFS) ReadTags(path ...string) (map[string]metadata.Info, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.FileInfo = localFileInfo{info}
|
||||
v.FileInfo = newLocalFileInfo(info)
|
||||
res[path] = v
|
||||
}
|
||||
}
|
||||
|
@ -77,15 +77,31 @@ func (lfs *localFS) ReadTags(path ...string) (map[string]metadata.Info, error) {
|
|||
// with metadata.FileInfo
|
||||
type localFileInfo struct {
|
||||
fs.FileInfo
|
||||
ts times.Timespec
|
||||
}
|
||||
|
||||
// newLocalFileInfo creates a localFileInfo with preloaded time information
|
||||
func newLocalFileInfo(info fs.FileInfo) localFileInfo {
|
||||
return localFileInfo{
|
||||
FileInfo: info,
|
||||
ts: times.Get(info),
|
||||
}
|
||||
}
|
||||
|
||||
func (lfi localFileInfo) BirthTime() time.Time {
|
||||
if ts := times.Get(lfi.FileInfo); ts.HasBirthTime() {
|
||||
return ts.BirthTime()
|
||||
if lfi.ts.HasBirthTime() {
|
||||
return lfi.ts.BirthTime()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (lfi localFileInfo) ChangeTime() time.Time {
|
||||
if lfi.ts.HasChangeTime() {
|
||||
return lfi.ts.ChangeTime()
|
||||
}
|
||||
return lfi.ModTime()
|
||||
}
|
||||
|
||||
func init() {
|
||||
storage.Register(storage.LocalSchemaID, newLocalStorage)
|
||||
}
|
||||
|
|
|
@ -83,10 +83,8 @@ type Metadata struct {
|
|||
hasPicture bool
|
||||
}
|
||||
|
||||
func (md Metadata) FilePath() string { return md.filePath }
|
||||
func (md Metadata) ModTime() time.Time { return md.fileInfo.ModTime() }
|
||||
func (md Metadata) BirthTime() time.Time { return md.fileInfo.BirthTime() }
|
||||
func (md Metadata) Size() int64 { return md.fileInfo.Size() }
|
||||
func (md Metadata) FilePath() string { return md.filePath }
|
||||
func (md Metadata) Size() int64 { return md.fileInfo.Size() }
|
||||
func (md Metadata) Suffix() string {
|
||||
return strings.ToLower(strings.TrimPrefix(path.Ext(md.filePath), "."))
|
||||
}
|
||||
|
@ -100,6 +98,18 @@ func (md Metadata) Int(key model.TagName) int64 { v, _ := strconv.A
|
|||
func (md Metadata) Bool(key model.TagName) bool { v, _ := strconv.ParseBool(md.first(key)); return v }
|
||||
func (md Metadata) Date(key model.TagName) Date { return md.date(key) }
|
||||
func (md Metadata) NumAndTotal(key model.TagName) (int, int) { return md.tuple(key) }
|
||||
|
||||
func (md Metadata) BirthTime() time.Time { return md.fileInfo.BirthTime() }
|
||||
func (md Metadata) ModTime() time.Time {
|
||||
type ChangeTimer interface {
|
||||
ChangeTime() time.Time
|
||||
}
|
||||
if ct, ok := md.fileInfo.(ChangeTimer); ok {
|
||||
return ct.ChangeTime()
|
||||
}
|
||||
return md.fileInfo.ModTime()
|
||||
}
|
||||
|
||||
func (md Metadata) Float(key model.TagName, def ...float64) float64 {
|
||||
return float(md.first(key), def...)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue