agendafs

A filesystem for your calendar.

git clone git://mccd.space/agendafs
commit ac06d189ee4f09bb40e2dff1d1fb8b6401f07032
parent 3e9ad1f5addff1205b8b90f1a1790dfe459abec0
Author: Marc Coquand <marc@coquand.email>
Date:   Sat, 31 May 2025 22:27:33 +0100

update specific file instead of all files

Diffstat:
Mmain.c | 22+++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -755,6 +755,12 @@ void update_or_add_entry(const char *filename)
 	const char *base_name = strrchr(filename, '/');
 	base_name = base_name ? base_name + 1 : filename;
 	journal_entry *entry = hashmap_get(entries_original_key, base_name);
+	if (!entry) {
+		LOG("COULD NOT FIND entry");
+		perror("calloc");
+		pthread_mutex_unlock(&entries_mutex);
+		return;
+	}
 	journal_entry *new_entry = calloc(1, sizeof(journal_entry));
 	if (!new_entry) {
 		perror("calloc");
@@ -762,6 +768,8 @@ void update_or_add_entry(const char *filename)
 		return;
 	}
 
+	LOG("Parsing ICS file %s", filename);
+
 	if (parse_ics_file(filename, new_entry) != 0) {
 		// Parsing failed, clean up and maybe remove old entry if any
 		free_journal_entry(new_entry);
@@ -773,7 +781,9 @@ void update_or_add_entry(const char *filename)
 	new_entry->filename_original =
 	    strndup(entry->filename_original, strlen(entry->filename));
 
-	hashmap_insert(entries_fuse_key, strdup(filename), new_entry);
+	hashmap_insert(entries_original_key, filename, new_entry);
+	hashmap_insert(entries_fuse_key, filename, new_entry);
+	LOG("File updated");
 
 	pthread_mutex_unlock(&entries_mutex);
 }
@@ -811,11 +821,17 @@ void *watch_ics_dir(void *arg)
 			struct inotify_event *event =
 			    (struct inotify_event *)&buffer[i];
 
+			char full_path[1024]; // Adjust size based on your max
+					      // path length
+			snprintf(full_path, sizeof(full_path), "%s/%s", ICS_DIR,
+				 event->name);
+
 			if (event->len && strstr(event->name, ".ics")) {
 				printf("Detected change in ICS file: %s\n",
 				       event->name);
-				load_journal_entries(); // Reload entries on any
-							// change
+				update_or_add_entry(
+				    full_path); // Reload entries on any
+						// change
 				break;
 			}