mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 08:05:56 -05:00
[directories] Initialize root directories on db init
This commit is contained in:
parent
7678f98879
commit
1a6565e512
14
src/db.c
14
src/db.c
@ -718,7 +718,7 @@ db_purge_cruft(time_t ref)
|
|||||||
"DELETE FROM playlistitems WHERE playlistid IN (SELECT id FROM playlists p WHERE p.type <> %d AND p.db_timestamp < %" PRIi64 ");",
|
"DELETE FROM playlistitems WHERE playlistid IN (SELECT id FROM playlists p WHERE p.type <> %d AND p.db_timestamp < %" PRIi64 ");",
|
||||||
"DELETE FROM playlists WHERE type <> %d AND db_timestamp < %" PRIi64 ";",
|
"DELETE FROM playlists WHERE type <> %d AND db_timestamp < %" PRIi64 ";",
|
||||||
"DELETE FROM files WHERE -1 <> %d AND db_timestamp < %" PRIi64 ";",
|
"DELETE FROM files WHERE -1 <> %d AND db_timestamp < %" PRIi64 ";",
|
||||||
"DELETE FROM directories WHERE id > 1 AND -1 <> %d AND db_timestamp < %" PRIi64 ";"
|
"DELETE FROM directories WHERE id > 4 AND -1 <> %d AND db_timestamp < %" PRIi64 ";"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sizeof(queries) != sizeof(queries_tmpl))
|
if (sizeof(queries) != sizeof(queries_tmpl))
|
||||||
@ -4963,6 +4963,15 @@ db_perthread_deinit(void)
|
|||||||
#define Q_DIR1 \
|
#define Q_DIR1 \
|
||||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
" VALUES (1, '/', 0, 0, 0);"
|
" VALUES (1, '/', 0, 0, 0);"
|
||||||
|
#define Q_DIR2 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (2, '/file:', 0, 0, 1);"
|
||||||
|
#define Q_DIR3 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (3, '/http:', 0, 0, 1);"
|
||||||
|
#define Q_DIR4 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (4, '/spotify:', 0, 0, 1);"
|
||||||
|
|
||||||
/* Rule of thumb: Will the current version of forked-daapd work with the new
|
/* Rule of thumb: Will the current version of forked-daapd work with the new
|
||||||
* version of the database? If yes, then it is a minor upgrade, if no, then it
|
* version of the database? If yes, then it is a minor upgrade, if no, then it
|
||||||
@ -5002,6 +5011,9 @@ static const struct db_init_query db_init_table_queries[] =
|
|||||||
{ Q_PL5, "create default smart playlist 'Podcasts'" },
|
{ Q_PL5, "create default smart playlist 'Podcasts'" },
|
||||||
{ Q_PL6, "create default smart playlist 'Audiobooks'" },
|
{ Q_PL6, "create default smart playlist 'Audiobooks'" },
|
||||||
{ Q_DIR1, "create default root directory '/'" },
|
{ Q_DIR1, "create default root directory '/'" },
|
||||||
|
{ Q_DIR2, "create default base directory '/file:'" },
|
||||||
|
{ Q_DIR3, "create default base directory '/http:'" },
|
||||||
|
{ Q_DIR4, "create default base directory '/spotify:'" },
|
||||||
|
|
||||||
{ Q_SCVER_MAJOR, "set schema version major" },
|
{ Q_SCVER_MAJOR, "set schema version major" },
|
||||||
{ Q_SCVER_MINOR, "set schema version minor" },
|
{ Q_SCVER_MINOR, "set schema version minor" },
|
||||||
|
8
src/db.h
8
src/db.h
@ -346,6 +346,14 @@ struct filecount_info {
|
|||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Directory ids must be in sync with the ids in Q_DIR* in db.c */
|
||||||
|
enum directory_ids {
|
||||||
|
DIR_ROOT = 1,
|
||||||
|
DIR_FILE = 2,
|
||||||
|
DIR_HTTP = 3,
|
||||||
|
DIR_SPOTIFY = 4,
|
||||||
|
};
|
||||||
|
|
||||||
struct directory_info {
|
struct directory_info {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
char *virtual_path;
|
char *virtual_path;
|
||||||
|
@ -1190,6 +1190,15 @@ static const struct db_upgrade_query db_upgrade_v1801_queries[] =
|
|||||||
#define U_V1900_INSERT_DIR1 \
|
#define U_V1900_INSERT_DIR1 \
|
||||||
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
" VALUES (1, '/', 0, 0, 0);"
|
" VALUES (1, '/', 0, 0, 0);"
|
||||||
|
#define U_V1900_INSERT_DIR2 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (2, '/file:', 0, 0, 1);"
|
||||||
|
#define U_V1900_INSERT_DIR3 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (3, '/http:', 0, 0, 1);"
|
||||||
|
#define U_V1900_INSERT_DIR4 \
|
||||||
|
"INSERT INTO directories (id, virtual_path, db_timestamp, disabled, parent_id)" \
|
||||||
|
" VALUES (4, '/spotify:', 0, 0, 1);"
|
||||||
|
|
||||||
#define U_V1900_SCVER_MAJOR \
|
#define U_V1900_SCVER_MAJOR \
|
||||||
"UPDATE admin SET value = '19' WHERE key = 'schema_version_major';"
|
"UPDATE admin SET value = '19' WHERE key = 'schema_version_major';"
|
||||||
@ -1202,6 +1211,9 @@ static const struct db_upgrade_query db_upgrade_v1900_queries[] =
|
|||||||
{ U_V1900_ALTER_PL_ADD_DIRECTORYID, "alter table pl add column directory_id" },
|
{ U_V1900_ALTER_PL_ADD_DIRECTORYID, "alter table pl add column directory_id" },
|
||||||
{ U_V1900_ALTER_FILES_ADD_DIRECTORYID, "alter table files add column directory_id" },
|
{ U_V1900_ALTER_FILES_ADD_DIRECTORYID, "alter table files add column directory_id" },
|
||||||
{ U_V1900_INSERT_DIR1, "insert root directory" },
|
{ U_V1900_INSERT_DIR1, "insert root directory" },
|
||||||
|
{ U_V1900_INSERT_DIR2, "insert /file: directory" },
|
||||||
|
{ U_V1900_INSERT_DIR3, "insert /htttp: directory" },
|
||||||
|
{ U_V1900_INSERT_DIR4, "insert /spotify: directory" },
|
||||||
{ U_V1900_DROP_VIEW_FILELIST, "drop view directories" },
|
{ U_V1900_DROP_VIEW_FILELIST, "drop view directories" },
|
||||||
|
|
||||||
{ U_V1900_SCVER_MAJOR, "set schema_version_major to 19" },
|
{ U_V1900_SCVER_MAJOR, "set schema_version_major to 19" },
|
||||||
|
@ -1156,10 +1156,9 @@ process_parent_directories(char *path)
|
|||||||
char virtual_path[PATH_MAX];
|
char virtual_path[PATH_MAX];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// The root directoy ID
|
dir_id = DIR_FILE;
|
||||||
dir_id = 1;
|
|
||||||
|
|
||||||
ptr = path;
|
ptr = path + 1;
|
||||||
while (ptr && (ptr = strchr(ptr, '/')))
|
while (ptr && (ptr = strchr(ptr, '/')))
|
||||||
{
|
{
|
||||||
strncpy(buf, path, (ptr - path));
|
strncpy(buf, path, (ptr - path));
|
||||||
|
@ -93,7 +93,6 @@ scan_playlist(char *file, time_t mtime, int dir_id)
|
|||||||
int ret;
|
int ret;
|
||||||
char virtual_path[PATH_MAX];
|
char virtual_path[PATH_MAX];
|
||||||
int i;
|
int i;
|
||||||
int di_id;
|
|
||||||
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Processing static playlist: %s\n", file);
|
DPRINTF(E_LOG, L_SCAN, "Processing static playlist: %s\n", file);
|
||||||
|
|
||||||
@ -239,13 +238,7 @@ scan_playlist(char *file, time_t mtime, int dir_id)
|
|||||||
if (extinf)
|
if (extinf)
|
||||||
DPRINTF(E_INFO, L_SCAN, "Playlist has EXTINF metadata, artist is '%s', title is '%s'\n", mfi.artist, mfi.title);
|
DPRINTF(E_INFO, L_SCAN, "Playlist has EXTINF metadata, artist is '%s', title is '%s'\n", mfi.artist, mfi.title);
|
||||||
|
|
||||||
di_id = db_directory_addorupdate("/http:", 0, 1);
|
filescanner_process_media(filename, mtime, 0, F_SCAN_TYPE_URL, &mfi, DIR_HTTP);
|
||||||
if (di_id <= 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Insert or update of directory failed '/http:'\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
filescanner_process_media(filename, mtime, 0, F_SCAN_TYPE_URL, &mfi, di_id);
|
|
||||||
}
|
}
|
||||||
/* Regular file, should already be in library */
|
/* Regular file, should already be in library */
|
||||||
else
|
else
|
||||||
|
@ -622,16 +622,8 @@ spotify_track_save(int plid, sp_track *track, const char *pltitle, int time_adde
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(virtual_path, sizeof(virtual_path), "/spotify:");
|
|
||||||
dir_id = db_directory_addorupdate(virtual_path, 0, 1);
|
|
||||||
if (dir_id <= 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not add or update directory '%s'\n", virtual_path);
|
|
||||||
free_mfi(&mfi, 1);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
snprintf(virtual_path, sizeof(virtual_path), "/spotify:/%s", mfi.artist);
|
snprintf(virtual_path, sizeof(virtual_path), "/spotify:/%s", mfi.artist);
|
||||||
dir_id = db_directory_addorupdate(virtual_path, 0, dir_id);
|
dir_id = db_directory_addorupdate(virtual_path, 0, DIR_SPOTIFY);
|
||||||
if (dir_id <= 0)
|
if (dir_id <= 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not add or update directory '%s'\n", virtual_path);
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not add or update directory '%s'\n", virtual_path);
|
||||||
@ -701,7 +693,6 @@ spotify_playlist_save(sp_playlist *pl)
|
|||||||
int created;
|
int created;
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
int dir_id;
|
|
||||||
|
|
||||||
if (!fptr_sp_playlist_is_loaded(pl))
|
if (!fptr_sp_playlist_is_loaded(pl))
|
||||||
{
|
{
|
||||||
@ -782,15 +773,6 @@ spotify_playlist_save(sp_playlist *pl)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir_id = db_directory_addorupdate("/spotify:", 0, 1);
|
|
||||||
if (dir_id <= 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Insert or update of directory failed '/spotify:'\n");
|
|
||||||
|
|
||||||
free_pli(pli, 0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(pli, 0, sizeof(struct playlist_info));
|
memset(pli, 0, sizeof(struct playlist_info));
|
||||||
|
|
||||||
pli->type = PL_PLAIN;
|
pli->type = PL_PLAIN;
|
||||||
@ -798,7 +780,7 @@ spotify_playlist_save(sp_playlist *pl)
|
|||||||
pli->path = strdup(url);
|
pli->path = strdup(url);
|
||||||
pli->virtual_path = strdup(virtual_path);
|
pli->virtual_path = strdup(virtual_path);
|
||||||
pli->parent_id = g_base_plid;
|
pli->parent_id = g_base_plid;
|
||||||
pli->directory_id = dir_id;
|
pli->directory_id = DIR_SPOTIFY;
|
||||||
|
|
||||||
ret = db_pl_add(pli, &plid);
|
ret = db_pl_add(pli, &plid);
|
||||||
if ((ret < 0) || (plid < 1))
|
if ((ret < 0) || (plid < 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user