From 87aa24454d7ee00a93b89e9b765b673bc1dedabf Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Thu, 11 Jun 2009 15:24:10 +0200 Subject: [PATCH] Add watch-marking routines --- src/db.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/db.h | 6 +++++ 2 files changed, 73 insertions(+) diff --git a/src/db.c b/src/db.c index 2d21ca01..8bb169f7 100644 --- a/src/db.c +++ b/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 diff --git a/src/db.h b/src/db.h index f8c64f52..8b85b1fc 100644 --- a/src/db.h +++ b/src/db.h @@ -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);