mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-26 14:13:18 -05:00
Add watch-marking routines
This commit is contained in:
parent
56127b3ecc
commit
87aa24454d
67
src/db.c
67
src/db.c
@ -2334,6 +2334,73 @@ db_watch_get_bywd(struct watch_info *wi)
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
static void
|
||||
db_watch_mark_byquery(char *query)
|
||||
{
|
||||
char *errmsg;
|
||||
int ret;
|
||||
|
||||
DPRINTF(E_DBG, L_DB, "Running query '%s'\n", query);
|
||||
|
||||
errmsg = NULL;
|
||||
ret = sqlite3_exec(hdl, query, NULL, NULL, &errmsg);
|
||||
if (ret != SQLITE_OK)
|
||||
DPRINTF(E_LOG, L_DB, "Error marking watch: %s\n", errmsg);
|
||||
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
|
||||
void
|
||||
db_watch_mark_bypath(char *path, char *strip, uint32_t cookie)
|
||||
{
|
||||
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path = '%q';"
|
||||
char *query;
|
||||
int64_t disabled;
|
||||
int striplen;
|
||||
|
||||
disabled = (cookie != 0) ? cookie : INOTIFY_FAKE_COOKIE;
|
||||
striplen = strlen(strip) + 1;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, striplen, disabled, path);
|
||||
if (!query)
|
||||
{
|
||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
db_watch_mark_byquery(query);
|
||||
|
||||
sqlite3_free(query);
|
||||
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
void
|
||||
db_watch_mark_bymatch(char *path, char *strip, uint32_t cookie)
|
||||
{
|
||||
#define Q_TMPL "UPDATE inotify SET path = substr(path, %d), cookie = %" PRIi64 " WHERE path LIKE '%q/%%';"
|
||||
char *query;
|
||||
int64_t disabled;
|
||||
int striplen;
|
||||
|
||||
disabled = (cookie != 0) ? cookie : INOTIFY_FAKE_COOKIE;
|
||||
striplen = strlen(strip) + 1;
|
||||
|
||||
query = sqlite3_mprintf(Q_TMPL, striplen, disabled, path);
|
||||
if (!query)
|
||||
{
|
||||
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
db_watch_mark_byquery(query);
|
||||
|
||||
sqlite3_free(query);
|
||||
|
||||
#undef Q_TMPL
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
|
Loading…
x
Reference in New Issue
Block a user