agendafs
A filesystem for your calendar.
git clone git://mccd.space/agendafscommit 5fec2f1e0ff85e3a5d93f883e491bd901df90348
parent ac06d189ee4f09bb40e2dff1d1fb8b6401f07032
Author: Marc Coquand <marc@coquand.email>
Date: Sat, 31 May 2025 22:41:48 +0100
Fixes
Diffstat:
| M | main.c | | | 27 | +++++++++------------------ |
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/main.c b/main.c
@@ -17,12 +17,9 @@
#define LOG(fmt, ...) \
fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
-#define MAX_BASE_FILENAME_LEN (sizeof(unique_filename) - 1 - 11)
-
// Listening to file changes of the original content
#define EVENT_BUF_LEN (1024 * (sizeof(struct inotify_event) + 16))
-const char *display_date_fmt = "%b %d, %Y at %H:%M";
const char *date_title_fmt = "%Y%m%d-%H:%M";
regex_t regex_summary, regex_description, regex_dtstamp, regex_lastmod,
regex_uid;
@@ -155,7 +152,6 @@ static char *escape_text(const char *src)
return NULL;
size_t len = strlen(src);
- // Worst-case size (every char becomes \X): len * 2 + 1
char *escaped = calloc(len * 2 + 1, 1);
if (!escaped)
return NULL;
@@ -320,7 +316,6 @@ static int parse_ics_file(const char *file_path, journal_entry *entry)
return 0;
cleanup:
- // Cleanup in case of error
if (entry->summary)
free(entry->summary);
if (entry->description)
@@ -419,7 +414,6 @@ static void load_journal_entries()
snprintf(filepath, sizeof(filepath), "%s/%s", ICS_DIR,
entry->d_name);
- // Allocate memory for a new journal entry
journal_entry *new_entry =
calloc(1, sizeof(journal_entry));
if (!new_entry) {
@@ -448,7 +442,7 @@ static void load_journal_entries()
char *unique_filename = get_unique_filename(
new_entry->created_at, entries_fuse_key);
if (!unique_filename) {
- LOG("Failed to generate unique filename for %s",
+ LOG("Failed to generate filename for %s",
entry->d_name);
free(new_entry->filename_original);
free(new_entry);
@@ -463,8 +457,7 @@ static void load_journal_entries()
hashmap_insert(entries_original_key,
new_entry->filename_original,
new_entry) != 0) {
- LOG("Failed to insert entry into one of the "
- "hashmaps");
+ LOG("Failed to insert entry");
free(new_entry->filename);
free(new_entry->filename_original);
free(new_entry);
@@ -652,8 +645,7 @@ char *journal_entry_to_ical(const journal_entry *entry)
return ical;
}
-int update_journal_from_input_buffer(journal_entry *entry, const char *buf,
- size_t size)
+int update_entry_content(journal_entry *entry, const char *buf, size_t size)
{
char *copy = strndup(buf, size);
if (!copy)
@@ -683,8 +675,6 @@ int update_journal_from_input_buffer(journal_entry *entry, const char *buf,
return -ENOMEM;
}
- // Optional: parse timestamp here if needed
-
// Clean up old values
free(entry->summary);
free(entry->description);
@@ -707,8 +697,8 @@ static int journal_write(const char *path, const char *buf, size_t size,
return -ENOENT;
}
- // Update hashmap with input buffer
- int ret = update_journal_from_input_buffer(entry, buf, size);
+ // Update hashmap with input
+ int ret = update_entry_content(entry, buf, size);
if (ret != 0) {
pthread_mutex_unlock(&entries_mutex);
return ret;
@@ -749,14 +739,15 @@ static const struct fuse_operations journal_oper = {
.write = journal_write,
};
-void update_or_add_entry(const char *filename)
+void update_fuse_entry_from_original(const char *filename)
{
pthread_mutex_lock(&entries_mutex);
const char *base_name = strrchr(filename, '/');
base_name = base_name ? base_name + 1 : filename;
journal_entry *entry = hashmap_get(entries_original_key, base_name);
+ // TODO: Create entry when file is not found
if (!entry) {
- LOG("COULD NOT FIND entry");
+ LOG("Entry not found. Registering new file");
perror("calloc");
pthread_mutex_unlock(&entries_mutex);
return;
@@ -829,7 +820,7 @@ void *watch_ics_dir(void *arg)
if (event->len && strstr(event->name, ".ics")) {
printf("Detected change in ICS file: %s\n",
event->name);
- update_or_add_entry(
+ update_fuse_entry_from_original(
full_path); // Reload entries on any
// change
break;