Allow user to trigger full rescan with a .force-rescan file

This commit is contained in:
ejurgensen 2013-11-29 22:48:53 +01:00
parent 0fd65b285d
commit adc9c03763
4 changed files with 55 additions and 0 deletions

6
README
View File

@ -257,6 +257,12 @@ be offered until they've been scanned.
Changes to the library are reflected in real time after the initial scan. The
directories are monitored for changes and rescanned on the fly.
If you place a file with the filename ending .force-rescan in your library,
you can trigger a full rescan of your library. This will clear all music and
playlists from forked-daapd's database and initiate a fresh bulk scan. Pairing
and speaker information will be kept. Only use this for troubleshooting, it is
not necessary during normal operation.
Symlinks are supported and dereferenced. This does interact in tricky ways
with the above monitoring and rescanning, so you've been warned. Changes to
symlinks themselves won't be taken into account, or not the way you'd expect.

View File

@ -651,6 +651,36 @@ db_purge_cruft(time_t ref)
}
void
db_purge_all(void)
{
char *queries[4] =
{
"DELETE FROM inotify;",
"DELETE FROM playlistitems;",
"DELETE FROM playlists WHERE type <> 1;",
"DELETE FROM files;"
};
char *errmsg;
int i;
int ret;
for (i = 0; i < (sizeof(queries) / sizeof(queries[0])); i++)
{
DPRINTF(E_DBG, L_DB, "Running purge query '%s'\n", queries[i]);
ret = db_exec(queries[i], &errmsg);
if (ret != SQLITE_OK)
{
DPRINTF(E_LOG, L_DB, "Purge query %d error: %s\n", i, errmsg);
sqlite3_free(errmsg);
}
else
DPRINTF(E_DBG, L_DB, "Purged %d rows\n", sqlite3_changes(hdl));
}
}
static int
db_get_count(char *query)
{

View File

@ -295,6 +295,9 @@ db_hook_post_scan(void);
void
db_purge_cruft(time_t ref);
void
db_purge_all(void);
/* Queries */
int
db_query_start(struct query_params *qp);

View File

@ -90,6 +90,9 @@ static pthread_t tid_scan;
static struct deferred_pl *playlists;
static struct stacked_dir *dirstack;
/* Forward */
static void
bulk_scan(void);
static int
push_dir(struct stacked_dir **s, char *path)
@ -560,6 +563,19 @@ process_file(char *file, time_t mtime, off_t size, int type, int flags)
return;
}
else if (strcmp(ext, ".force-rescan") == 0)
{
if (flags & F_SCAN_BULK)
return;
else
{
DPRINTF(E_LOG, L_SCAN, "Forcing full rescan, found force-rescan file: %s\n", file);
db_purge_all();
bulk_scan();
return;
}
}
}
/* Not any kind of special file, so let's see if it's a media file */