agendafs

A filesystem for your calendar.

git clone git://mccd.space/agendafs
commit e7197cbae2801a2207e85ea9ccce155a873619dc
parent 01fe88ba8d6fc0bc990b446a94c0d3a55e2e4324
Author: Marc Coquand <marc@coquand.email>
Date:   Mon,  2 Jun 2025 10:15:19 +0100

Load from environment

Diffstat:
M.gitignore | 4++--
MMakefile | 4++--
Djournalfs | 0
Mmain.c | 45++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,2 @@
-caldavfs
-caldavfs-debug
+mount_caldavfs
+mount_caldavfs-debug
diff --git a/Makefile b/Makefile
@@ -6,10 +6,10 @@ LIBS = `pkg-config uuid fuse3 --cflags --libs`
 all: caldavfs
 
 caldavfs: main.c util.c hashmap.c
-	$(CC) $(CFLAGS) main.c util.c hashmap.c -o caldavfs $(LIBS)
+	$(CC) $(CFLAGS) main.c util.c hashmap.c -o mount_caldavfs $(LIBS)
 
 debug: main.c util.c hashmap.c
-	$(CC) $(CFLAGS_DEBUG) $(DEBUG_FLAGS) main.c util.c hashmap.c -o caldavfs-debug $(LIBS)
+	$(CC) $(CFLAGS_DEBUG) $(DEBUG_FLAGS) main.c util.c hashmap.c -o mount_caldavfs-debug $(LIBS)
 
 clean:
 	rm -f caldavfs caldavfs-debug
diff --git a/journalfs b/journalfs
Binary files differ.
diff --git a/main.c b/main.c
@@ -16,14 +16,15 @@
 #include <time.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
-
-#define ICS_DIR "/home/mccd/dev/fuse-journal/sample_ics"
+#include <wordexp.h>
 #define LOG(fmt, ...)                                                          \
 	fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
 
 // Listening to file changes of the original content
 #define EVENT_BUF_LEN (1024 * (sizeof(struct inotify_event) + 16))
 
+char ICS_DIR[256];
+
 const char *date_title_fmt = "%Y%m%d-%H:%M";
 regex_t regex_dtstamp, regex_lastmod, regex_fuse_file;
 
@@ -476,7 +477,7 @@ load_journal_entries()
 				continue;
 			}
 
-			LOG("Parsed entry");
+			LOG("Parsed %s", new_entry->filename_original);
 
 			// Generate a unique filename for the journal entry
 			char *unique_filename = get_unique_filename(
@@ -1133,11 +1134,49 @@ static const struct fuse_operations journal_oper = {.getattr = journal_getattr,
 						    .unlink = journal_unlink,
 						    .rename = journal_rename};
 
+size_t
+load_caldavfs_environment()
+{
+	char *ics_dir_env = getenv("CALDAVFS_ICS_DIR");
+
+	if (ics_dir_env == NULL) {
+		fprintf(
+		    stderr,
+		    "Must set CALDAVFS_ICS_DIR to the absolute path of your "
+		    "calendar. See README.\n");
+		return -1;
+	}
+
+	wordexp_t p;
+	if (wordexp(ics_dir_env, &p, 0) != 0 || p.we_wordc == 0) {
+		fprintf(stderr, "Failed to expand CALDAVFS_ICS_DIR\n");
+		wordfree(&p);
+		return -1;
+	}
+
+	char *expanded_path = p.we_wordv[0];
+
+	struct stat s;
+	if (stat(expanded_path, &s) == 0 && S_ISDIR(s.st_mode)) {
+		strlcpy(ICS_DIR, expanded_path, sizeof(ICS_DIR));
+		return 0;
+	}
+
+	fprintf(stderr, "CALDAVFS_ICS_DIR is not a directory: %s\n",
+		expanded_path);
+	return -1;
+}
+
 int
 main(int argc, char *argv[])
 {
 	pthread_t watcher_thread;
 
+	if (load_caldavfs_environment() != 0) {
+		fprintf(stderr, "Failed to load ICS directory\n");
+		exit(1);
+	}
+
 	if (pthread_create(&watcher_thread, NULL, watch_ics_dir, NULL) != 0) {
 		perror("Failed to create inotify watcher thread");
 		return 1;