Disable instead of purging when root library dir is not present

This commit is contained in:
ejurgensen 2013-11-30 23:12:09 +01:00
parent 414817031d
commit 8882374a75
5 changed files with 80 additions and 9 deletions

View File

@ -1645,12 +1645,13 @@ db_files_get_count(void)
}
int
db_files_get_count_bypathpattern(char *path)
db_files_get_count_bymatch(char *path)
{
#define Q_TMPL "SELECT COUNT(*) FROM files f WHERE f.path LIKE '%%%q';"
char *query;
int count;
query = sqlite3_mprintf("SELECT COUNT(*) FROM files f WHERE f.path LIKE '%%%q';", path);
query = sqlite3_mprintf(Q_TMPL, path);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory making count query string.\n");
@ -1662,6 +1663,7 @@ db_files_get_count_bypathpattern(char *path)
sqlite3_free(query);
return count;
#undef Q_TMPL
}
void
@ -1738,6 +1740,34 @@ db_file_ping(int id)
#undef Q_TMPL
}
void
db_file_ping_bymatch(char *path)
{
#define Q_TMPL "UPDATE files SET db_timestamp = %" PRIi64 " WHERE path LIKE '%q/%%';"
char *query;
char *errmsg;
int ret;
query = sqlite3_mprintf(Q_TMPL, (int64_t)time(NULL), path);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
return;
}
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
ret = db_exec(query, &errmsg);
if (ret != SQLITE_OK)
DPRINTF(E_LOG, L_DB, "Error pinging files matching %s: %s\n", path, errmsg);
sqlite3_free(errmsg);
sqlite3_free(query);
#undef Q_TMPL
}
char *
db_file_path_byid(int id)
{
@ -1864,7 +1894,7 @@ db_file_id_bypath(char *path)
}
int
db_file_id_bypathpattern(char *path)
db_file_id_bymatch(char *path)
{
#define Q_TMPL "SELECT f.id FROM files f WHERE f.path LIKE '%%%q';"
char *query;
@ -2520,6 +2550,34 @@ db_pl_ping(int id)
#undef Q_TMPL
}
void
db_pl_ping_bymatch(char *path)
{
#define Q_TMPL "UPDATE playlists SET db_timestamp = %" PRIi64 " WHERE path LIKE '%q/%%';"
char *query;
char *errmsg;
int ret;
query = sqlite3_mprintf(Q_TMPL, (int64_t)time(NULL), path);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
return;
}
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
ret = db_exec(query, &errmsg);
if (ret != SQLITE_OK)
DPRINTF(E_LOG, L_DB, "Error pinging playlists matching %s: %s\n", path, errmsg);
sqlite3_free(errmsg);
sqlite3_free(query);
#undef Q_TMPL
}
static int
db_pl_id_bypath(char *path, int *id)
{

View File

@ -325,7 +325,7 @@ int
db_files_get_count(void);
int
db_files_get_count_bypathpattern(char *path);
db_files_get_count_bymatch(char *path);
void
db_files_update_songalbumid(void);
@ -336,6 +336,9 @@ db_file_inc_playcount(int id);
void
db_file_ping(int id);
void
db_file_ping_bymatch(char *path);
char *
db_file_path_byid(int id);
@ -343,7 +346,7 @@ int
db_file_id_bypath(char *path);
int
db_file_id_bypathpattern(char *path);
db_file_id_bymatch(char *path);
int
db_file_id_byfilebase(char *filename, char *base);
@ -385,6 +388,9 @@ db_pl_get_count(void);
void
db_pl_ping(int id);
void
db_pl_ping_bymatch(char *path);
struct playlist_info *
db_pl_fetch_bypath(char *path);

View File

@ -847,6 +847,13 @@ bulk_scan(void)
{
DPRINTF(E_LOG, L_SCAN, "Skipping library directory %s, could not dereference: %s\n", path, strerror(errno));
/* Assume dir is mistakenly not mounted, so just disable everything and update timestamps */
db_file_disable_bymatch(path, "", 0);
db_pl_disable_bymatch(path, "", 0);
db_file_ping_bymatch(path);
db_pl_ping_bymatch(path);
continue;
}

View File

@ -301,13 +301,13 @@ find_track_file(char *location)
entry = location;
DPRINTF(E_SPAM, L_SCAN, "iTunes XML playlist entry is now %s\n", entry);
ret = db_files_get_count_bypathpattern(entry);
ret = db_files_get_count_bymatch(entry);
} while (ptr && (ret > 1));
if (ret > 0)
{
mfi_id = db_file_id_bypathpattern(entry);
mfi_id = db_file_id_bymatch(entry);
DPRINTF(E_DBG, L_SCAN, "Found iTunes XML playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
free(location);

View File

@ -242,13 +242,13 @@ scan_m3u_playlist(char *file, time_t mtime)
entry = buf;
DPRINTF(E_SPAM, L_SCAN, "Playlist entry is now %s\n", entry);
ret = db_files_get_count_bypathpattern(entry);
ret = db_files_get_count_bymatch(entry);
} while (ptr && (ret > 1));
if (ret > 0)
{
mfi_id = db_file_id_bypathpattern(entry);
mfi_id = db_file_id_bymatch(entry);
DPRINTF(E_DBG, L_SCAN, "Found playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
filename = db_file_path_byid(mfi_id);