Remove dangling tracks after changing MusicFolder. Fix #445
This commit is contained in:
@@ -108,7 +108,7 @@ func (r mediaFileRepository) FindAllByPath(path string) (model.MediaFiles, error
|
||||
return res, err
|
||||
}
|
||||
|
||||
func pathStartsWith(path string) Sqlizer {
|
||||
func pathStartsWith(path string) Eq {
|
||||
cleanPath := filepath.Clean(path)
|
||||
substr := fmt.Sprintf("substr(path, 1, %d)", utf8.RuneCountInString(cleanPath))
|
||||
return Eq{substr: cleanPath}
|
||||
@@ -124,6 +124,17 @@ func (r mediaFileRepository) FindPathsRecursively(basePath string) ([]string, er
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (r mediaFileRepository) deleteNotInPath(basePath string) error {
|
||||
sel := Delete(r.tableName).Where(NotEq(pathStartsWith(basePath)))
|
||||
c, err := r.executeSQL(sel)
|
||||
if err == nil {
|
||||
if c > 0 {
|
||||
log.Debug(r.ctx, "Deleted dangling tracks", "totalDeleted", c)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r mediaFileRepository) GetStarred(options ...model.QueryOptions) (model.MediaFiles, error) {
|
||||
sq := r.selectMediaFile(options...).Where("starred = true")
|
||||
starred := model.MediaFiles{}
|
||||
|
||||
Reference in New Issue
Block a user