Skip to content

Commit

Permalink
[db] add db_watch_enum_fetch() to return all watch_info
Browse files Browse the repository at this point in the history
  • Loading branch information
whatdoineed2do/Ray committed Jan 29, 2021
1 parent c97a25b commit f008e08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -6383,8 +6383,8 @@ db_watch_cookie_known(uint32_t cookie)
int
db_watch_enum_start(struct watch_enum *we)
{
#define Q_MATCH_TMPL "SELECT wd FROM inotify WHERE path LIKE '%q/%%';"
#define Q_COOKIE_TMPL "SELECT wd FROM inotify WHERE cookie = %" PRIi64 ";"
#define Q_MATCH_TMPL "SELECT wd,path FROM inotify WHERE path LIKE '%q/%%';"
#define Q_COOKIE_TMPL "SELECT wd,path FROM inotify WHERE cookie = %" PRIi64 ";"
sqlite3_stmt *stmt;
char *query;
int ret;
Expand Down Expand Up @@ -6469,6 +6469,40 @@ db_watch_enum_fetchwd(struct watch_enum *we, uint32_t *wd)
return 0;
}

int
db_watch_enum_fetch(struct watch_enum *we, struct watch_info *wi)
{
int ret;

wi->wd = 0;
wi->cookie = 0;

if (!we->stmt)
{
DPRINTF(E_LOG, L_DB, "Watch enum not started!\n");
return -1;
}

ret = db_blocking_step(we->stmt);
if (ret == SQLITE_DONE)
{
DPRINTF(E_INFO, L_DB, "End of watch enum results\n");
return 0;
}
else if (ret != SQLITE_ROW)
{
DPRINTF(E_LOG, L_DB, "Could not step: %s\n", sqlite3_errmsg(hdl));
return -1;
}

wi->wd = (uint32_t)sqlite3_column_int(we->stmt, 0);
if (wi->path)
snprintf(wi->path, PATH_MAX, (char*)sqlite3_column_text(we->stmt, 1));

return 0;
}



#ifdef DB_PROFILE
static int
Expand Down
3 changes: 3 additions & 0 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ db_watch_enum_end(struct watch_enum *we);
int
db_watch_enum_fetchwd(struct watch_enum *we, uint32_t *wd);

int
db_watch_enum_fetch(struct watch_enum *we, struct watch_info *wi);

int
db_backup();

Expand Down

0 comments on commit f008e08

Please sign in to comment.