agendafs

A filesystem for your calendar.

git clone git://mccd.space/agendafs
commit 0687368b70be16eb0593c1de843686501db9ee69
parent 27ec9083093cf039d9b0412b3333df16d2bfe4ec
Author: Marc Coquand <marc@coquand.email>
Date:   Thu,  5 Jun 2025 20:18:46 +0100

ugly code

Diffstat:
Mmain.c | 29++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/main.c b/main.c
@@ -95,19 +95,18 @@ get_entry_from_fuse_path(const char *path)
 		return NULL;
 	}
 
-	const char *prefix = "/journal/";
+	const char *prefix = "/entries/";
 	size_t prefix_len = strlen(prefix);
 
-	// Must start with "/journal/"
 	if (strncmp(path, prefix, prefix_len) != 0) {
-		LOG("Path does not start with '/journal/': '%s'\n", path);
+		LOG("Path does not start with '/entries/': '%s'\n", path);
 		return NULL;
 	}
 
-	// Extract the part after "/journal/"
+	// Extract the part after "/entries/"
 	const char *key = path + prefix_len;
 
-	// If key is empty (i.e., path is exactly "/journal/"), reject
+	// If key is empty (i.e., path is exactly "/entries/"), reject
 	if (strlen(key) == 0) {
 		LOG("Empty key in path: '%s'\n", path);
 		return NULL;
@@ -334,7 +333,7 @@ journal_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi)
 		goto unlock_and_return;
 	}
 
-	if (strcmp(path, "/journal") == 0) {
+	if (strcmp(path, "/entries") == 0) {
 		stbuf->st_mode = S_IFDIR | 0444;
 		stbuf->st_nlink = 2;
 		goto unlock_and_return;
@@ -412,7 +411,7 @@ journal_readlink(const char *path, char *buf, size_t size)
 			return -ENOENT;
 
 		// Return symlink target
-		snprintf(buf, size, "../journal/%s", key);
+		snprintf(buf, size, "../entries/%s", key);
 
 		pthread_mutex_unlock(&entries_mutex);
 		return 0;
@@ -432,10 +431,10 @@ journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 
 	// If we are in the root directory, expose the "journal" directory
 	if (strcmp(path, "/") == 0) {
-		filler(buf, "journal", NULL, 0, 0);
+		filler(buf, "entries", NULL, 0, 0);
 		filler(buf, "today", NULL, 0, 0);
 	}
-	else if (strcmp(path, "/journal") == 0) {
+	else if (strcmp(path, "/entries") == 0) {
 		size_t n_keys = 0;
 		char **keys = hashmap_get_keys(entries_fuse_key, &n_keys);
 		if (!keys) {
@@ -450,9 +449,6 @@ journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 		hashmap_free_keys(keys, n_keys);
 	}
 	else if (strcmp(path, "/today") == 0) {
-		time_t now = time(NULL);
-		struct tm *now_tm = localtime(&now);
-
 		size_t n_keys = 0;
 		char **keys = hashmap_get_keys(entries_fuse_key, &n_keys);
 		if (!keys) {
@@ -473,11 +469,10 @@ journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 
 			struct icaltimetype dt =
 			    icalcomponent_get_dtstamp(component);
-			if (dt.year == (now_tm->tm_year + 1900) &&
-			    dt.month == (now_tm->tm_mon + 1) &&
-			    dt.day == now_tm->tm_mday) {
-				filler(buf, keys[i], NULL, 0,
-				       0); // same name as in /journal
+
+			if (icaltime_compare_date_only(dt, icaltime_today()) ==
+			    0) {
+				filler(buf, keys[i], NULL, 0, 0);
 			}
 		}