[scan] Fix missing rescan if a file is modified quickly multiple times

If db_timestamp == file_mtime we didn't rescan, just pinged the file in the db

Fixes #1782
This commit is contained in:
ejurgensen 2024-07-26 16:04:01 +02:00
parent 90a79090ea
commit 59bba5e261
2 changed files with 8 additions and 3 deletions

View File

@ -7055,7 +7055,10 @@ db_statements_prepare_ping(const char *table)
sqlite3_stmt *stmt;
int ret;
CHECK_NULL(L_DB, query = db_mprintf("UPDATE %s SET db_timestamp = ?, disabled = 0 WHERE path = ? AND db_timestamp >= ?;", table));
// The last param will be the file mtime. We must not update if the mtime is
// newer or equal than the current db_timestamp, since the file may have been
// modified and must be rescanned.
CHECK_NULL(L_DB, query = db_mprintf("UPDATE %s SET db_timestamp = ?, disabled = 0 WHERE path = ? AND db_timestamp > ?;", table));
ret = db_blocking_prepare_v2(query, -1, &stmt, NULL);
if (ret != SQLITE_OK)

View File

@ -572,10 +572,12 @@ process_regular_file(const char *file, struct stat *sb, int type, int flags, int
char virtual_path[PATH_MAX];
int ret;
// Will return 0 if file is not in library or if file mtime is newer than library timestamp
// - note if mtime is 0 then we always scan the file
if (!(flags & F_SCAN_METARESCAN))
{
// Will return 0 if file is not in library or if file mtime is not older
// than the library timestamp. If mtime is equal we must rescan, since a
// fast update may have been made, see issue #1782. If mtime is 0 then we
// always scan.
ret = db_file_ping_bypath(file, sb->st_mtime);
if ((sb->st_mtime != 0) && (ret != 0))
return;