mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 15:45:56 -05:00
Disable instead of purging when root library dir is not present
This commit is contained in:
parent
414817031d
commit
8882374a75
64
src/db.c
64
src/db.c
@ -1645,12 +1645,13 @@ db_files_get_count(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
char *query;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
query = sqlite3_mprintf("SELECT COUNT(*) FROM files f WHERE f.path LIKE '%%%q';", path);
|
query = sqlite3_mprintf(Q_TMPL, path);
|
||||||
if (!query)
|
if (!query)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_DB, "Out of memory making count query string.\n");
|
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);
|
sqlite3_free(query);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
#undef Q_TMPL
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1738,6 +1740,34 @@ db_file_ping(int id)
|
|||||||
#undef Q_TMPL
|
#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 *
|
char *
|
||||||
db_file_path_byid(int id)
|
db_file_path_byid(int id)
|
||||||
{
|
{
|
||||||
@ -1864,7 +1894,7 @@ db_file_id_bypath(char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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';"
|
#define Q_TMPL "SELECT f.id FROM files f WHERE f.path LIKE '%%%q';"
|
||||||
char *query;
|
char *query;
|
||||||
@ -2520,6 +2550,34 @@ db_pl_ping(int id)
|
|||||||
#undef Q_TMPL
|
#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
|
static int
|
||||||
db_pl_id_bypath(char *path, int *id)
|
db_pl_id_bypath(char *path, int *id)
|
||||||
{
|
{
|
||||||
|
10
src/db.h
10
src/db.h
@ -325,7 +325,7 @@ int
|
|||||||
db_files_get_count(void);
|
db_files_get_count(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_files_get_count_bypathpattern(char *path);
|
db_files_get_count_bymatch(char *path);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_files_update_songalbumid(void);
|
db_files_update_songalbumid(void);
|
||||||
@ -336,6 +336,9 @@ db_file_inc_playcount(int id);
|
|||||||
void
|
void
|
||||||
db_file_ping(int id);
|
db_file_ping(int id);
|
||||||
|
|
||||||
|
void
|
||||||
|
db_file_ping_bymatch(char *path);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
db_file_path_byid(int id);
|
db_file_path_byid(int id);
|
||||||
|
|
||||||
@ -343,7 +346,7 @@ int
|
|||||||
db_file_id_bypath(char *path);
|
db_file_id_bypath(char *path);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_file_id_bypathpattern(char *path);
|
db_file_id_bymatch(char *path);
|
||||||
|
|
||||||
int
|
int
|
||||||
db_file_id_byfilebase(char *filename, char *base);
|
db_file_id_byfilebase(char *filename, char *base);
|
||||||
@ -385,6 +388,9 @@ db_pl_get_count(void);
|
|||||||
void
|
void
|
||||||
db_pl_ping(int id);
|
db_pl_ping(int id);
|
||||||
|
|
||||||
|
void
|
||||||
|
db_pl_ping_bymatch(char *path);
|
||||||
|
|
||||||
struct playlist_info *
|
struct playlist_info *
|
||||||
db_pl_fetch_bypath(char *path);
|
db_pl_fetch_bypath(char *path);
|
||||||
|
|
||||||
|
@ -847,6 +847,13 @@ bulk_scan(void)
|
|||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Skipping library directory %s, could not dereference: %s\n", path, strerror(errno));
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,13 +301,13 @@ find_track_file(char *location)
|
|||||||
entry = location;
|
entry = location;
|
||||||
|
|
||||||
DPRINTF(E_SPAM, L_SCAN, "iTunes XML playlist entry is now %s\n", entry);
|
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));
|
} while (ptr && (ret > 1));
|
||||||
|
|
||||||
if (ret > 0)
|
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);
|
DPRINTF(E_DBG, L_SCAN, "Found iTunes XML playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
|
||||||
|
|
||||||
free(location);
|
free(location);
|
||||||
|
@ -242,13 +242,13 @@ scan_m3u_playlist(char *file, time_t mtime)
|
|||||||
entry = buf;
|
entry = buf;
|
||||||
|
|
||||||
DPRINTF(E_SPAM, L_SCAN, "Playlist entry is now %s\n", entry);
|
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));
|
} while (ptr && (ret > 1));
|
||||||
|
|
||||||
if (ret > 0)
|
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);
|
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);
|
filename = db_file_path_byid(mfi_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user