summary refs log tree commit diff
path: root/contrib/palaver
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/palaver')
-rw-r--r--contrib/palaver/notify.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/contrib/palaver/notify.c b/contrib/palaver/notify.c
index 8572567..a8ca220 100644
--- a/contrib/palaver/notify.c
+++ b/contrib/palaver/notify.c
@@ -58,16 +58,8 @@ static CURL *curl;
 static sqlite3 *db;
 static struct tls *client;
 
-static void dbOpen(char *path) {
-	char *base = strrchr(path, '/');
-	*base = '\0';
-	int error = mkdir(path, 0700);
-	if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", path);
-	*base = '/';
-
-	error = sqlite3_open_v2(
-		path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL
-	);
+static void dbOpen(const char *path, int flags) {
+	int error = sqlite3_open_v2(path, &db, flags, NULL);
 	if (error == SQLITE_CANTOPEN) {
 		sqlite3_close(db);
 		db = NULL;
@@ -80,7 +72,7 @@ static void dbOpen(char *path) {
 
 static void dbFind(char *path) {
 	if (path) {
-		dbOpen(path);
+		dbOpen(path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
 		if (db) return;
 		errx(EX_NOINPUT, "%s: database not found", path);
 	}
@@ -88,6 +80,7 @@ static void dbFind(char *path) {
 	const char *home = getenv("HOME");
 	const char *dataHome = getenv("XDG_DATA_HOME");
 	const char *dataDirs = getenv("XDG_DATA_DIRS");
+	if (!dataDirs) dataDirs = "/usr/local/share:/usr/share";
 
 	char buf[PATH_MAX];
 	if (dataHome) {
@@ -96,19 +89,29 @@ static void dbFind(char *path) {
 		if (!home) errx(EX_CONFIG, "HOME unset");
 		snprintf(buf, sizeof(buf), "%s/.local/share/" DATABASE_PATH, home);
 	}
-	dbOpen(buf);
+	dbOpen(buf, SQLITE_OPEN_READWRITE);
 	if (db) return;
 
-	if (!dataDirs) dataDirs = "/usr/local/share:/usr/share";
+	char create[PATH_MAX];
+	snprintf(create, sizeof(create), "%s", buf);
+
 	while (*dataDirs) {
 		size_t len = strcspn(dataDirs, ":");
 		snprintf(buf, sizeof(buf), "%.*s/" DATABASE_PATH, (int)len, dataDirs);
-		dbOpen(buf);
+		dbOpen(buf, SQLITE_OPEN_READWRITE);
 		if (db) return;
 		dataDirs += len;
 		if (*dataDirs) dataDirs++;
 	}
-	errx(EX_NOINPUT, "database not found");
+
+	char *base = strrchr(create, '/');
+	*base = '\0';
+	int error = mkdir(create, 0700);
+	if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", create);
+	*base = '/';
+
+	dbOpen(create, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+	if (!db) errx(EX_CANTCREAT, "%s: cannot create database", create);
 }
 
 static int dbParam(sqlite3_stmt *stmt, const char *param) {
-highlight'> 2021-01-13Match [] as Operator in C lexerJune McEnroe 2021-01-13Fix C lexer to require a digit in a float literalJune McEnroe Otherwise ".l" is matched as Number. 2021-01-13Support long double in c.shJune McEnroe 2021-01-13Update Terminal.app coloursJune McEnroe God what is this garbage I only changed one colour. 2021-01-13Increase dark white brightness slightlyJune McEnroe 2021-01-13Add hilex example to htagml manualJune McEnroe 2021-01-12Style causal.agency like bin HTMLJune McEnroe 2021-01-12Avoid matching tag text inside HTML elementsJune McEnroe 2021-01-12Use hilex for up -hJune McEnroe 2021-01-12Use hilex for bin HTMLJune McEnroe 2021-01-12Don't output a pre in hilex by defaultJune McEnroe 2021-01-12Move hilex out of hilex directoryJune McEnroe 2021-01-12Consolidate hilex formatters into hilex.cJune McEnroe 2021-01-12Remove hacky tagging from hilexJune McEnroe God that makes the lexers so much simpler. 2021-01-12Add htagml -iJune McEnroe 2021-01-12Render tag index in HTMLJune McEnroe 2021-01-12Add htagml -xJune McEnroe 2021-01-12Prevent matching the same tag twiceJune McEnroe 2021-01-12Process htagml file line by lineJune McEnroe This simplifies some things, adds support for line number tag definitions, and should enable combining htagml with other preprocessors in the future. 2021-01-12Split fields by tab onlyJune McEnroe Also don't fail hard on non-forward-search definitions. 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe neovim is laggy as hell in my OpenBSD VM, so I switched to vi so I could type without getting frustrated. 2021-01-09Add c -t flag to print expression typeJune McEnroe Also add missing float case. 2021-01-05Update taglineJune McEnroe