From 7fd758a4a9b99d79a4c490257f16b2fce506b21c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 23 Dec 2019 21:53:24 -0500 Subject: Take optional explicit path in dbFind --- database.h | 16 +++++++++------- litterbox.c | 2 +- unscoop.c | 4 +--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/database.h b/database.h index 1dcc71b..1d5ef1c 100644 --- a/database.h +++ b/database.h @@ -74,26 +74,28 @@ static inline sqlite3 *dbOpen(char *path, int flags) { return db; } -static inline sqlite3 *dbFind(int flags) { +static inline sqlite3 *dbFind(char *path, int flags) { + if (path) return dbOpen(path, flags); + const char *home = getenv("HOME"); const char *dataHome = getenv("XDG_DATA_HOME"); const char *dataDirs = getenv("XDG_DATA_DIRS"); - char path[PATH_MAX]; + char buf[PATH_MAX]; if (dataHome) { - snprintf(path, sizeof(path), "%s/" DATABASE_PATH, dataHome); + snprintf(buf, sizeof(buf), "%s/" DATABASE_PATH, dataHome); } else { if (!home) errx(EX_CONFIG, "HOME unset"); - snprintf(path, sizeof(path), "%s/.local/share/" DATABASE_PATH, home); + snprintf(buf, sizeof(buf), "%s/.local/share/" DATABASE_PATH, home); } - sqlite3 *db = dbOpen(path, flags); + sqlite3 *db = dbOpen(buf, flags); if (db) return db; if (!dataDirs) dataDirs = "/usr/local/share:/usr/share"; while (*dataDirs) { size_t len = strcspn(dataDirs, ":"); - snprintf(path, sizeof(path), "%.*s/" DATABASE_PATH, (int)len, dataDirs); - db = dbOpen(path, flags); + snprintf(buf, sizeof(buf), "%.*s/" DATABASE_PATH, (int)len, dataDirs); + db = dbOpen(buf, flags); if (db) return db; dataDirs += len; if (*dataDirs) dataDirs++; diff --git a/litterbox.c b/litterbox.c index 178f790..8015cec 100644 --- a/litterbox.c +++ b/litterbox.c @@ -410,7 +410,7 @@ int main(int argc, char *argv[]) { int flags = SQLITE_OPEN_READWRITE; if (init) flags |= SQLITE_OPEN_CREATE; - db = (path ? dbOpen(path, flags) : dbFind(flags)); + db = dbFind(path, flags); if (!db) errx(EX_NOINPUT, "database not found"); if (init) { diff --git a/unscoop.c b/unscoop.c index 996b929..0b15430 100644 --- a/unscoop.c +++ b/unscoop.c @@ -317,10 +317,8 @@ int main(int argc, char *argv[]) { } } - int flags = SQLITE_OPEN_READWRITE; - sqlite3 *db = (path ? dbOpen(path, flags) : dbFind(flags)); + sqlite3 *db = dbFind(path, SQLITE_OPEN_READWRITE); if (!db) errx(EX_NOINPUT, "database not found"); - if (dbVersion(db) != DatabaseVersion) { errx(EX_CONFIG, "database out of date; migrate with litterbox -m"); } -- cgit 1.4.1 e62&follow=1'>server.c (unfollow)
Commit message (Expand)Author
2017-07-30Add index.htmlJune McEnroe
2017-07-30Add snapshot.shJune McEnroe
2017-07-30Fix termcap patch for background colorsJune McEnroe
2017-07-30Update helpJune McEnroe
2017-07-30Fix help to track colorJune McEnroe
2017-07-30Support background colorsJune McEnroe
2017-07-30Track color only client-sideJune McEnroe
2017-07-30Add ostensible support for background colorsJune McEnroe
2017-07-30Add tile create and access timestampsJune McEnroe
2017-07-30Assert stable struct Tile field offsetsJune McEnroe
2017-07-30Add chroot.shJune McEnroe
2017-07-30Add ` commandJune McEnroe
2017-07-30Add sshd_configJune McEnroe
2017-07-30Add termcap patchJune McEnroe