From 59bba5e261b6284b4172ffbf60e583a3dcc26cd9 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Fri, 26 Jul 2024 16:04:01 +0200 Subject: [PATCH] [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 --- src/db.c | 5 ++++- src/library/filescanner.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index 8b23af16..0dc32c38 100644 --- a/src/db.c +++ b/src/db.c @@ -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) diff --git a/src/library/filescanner.c b/src/library/filescanner.c index 2bb208b4..ffcf9e59 100644 --- a/src/library/filescanner.c +++ b/src/library/filescanner.c @@ -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;