Add watch-marking routines

This commit is contained in:
Julien BLACHE 2009-06-11 15:24:10 +02:00
parent 56127b3ecc
commit 87aa24454d
2 changed files with 73 additions and 0 deletions

View File

@ -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

View File

@ -299,6 +299,12 @@ db_watch_delete_bywd(struct watch_info *wi);
int
db_watch_get_bywd(struct watch_info *wi);
void
db_watch_mark_bypath(char *path, char *strip, uint32_t cookie);
void
db_watch_mark_bymatch(char *path, char *strip, uint32_t cookie);
int
db_perthread_init(void);