agendafs
A filesystem for your calendar.
git clone git://mccd.space/agendafscommit 762bf678883e738c313ba35bd89143287c5c3c86
parent 3c47ec5ec1bc903142f87bca201e7e9feb4057ba
Author: Marc Coquand <marc@coquand.email>
Date: Fri, 11 Jul 2025 09:35:38 +0200
Refactor; verify node is different before moving
Fixes: https://todo.sr.ht/~marcc/agendafs/22
Diffstat:
3 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/journal_entry.c b/journal_entry.c
@@ -125,6 +125,15 @@ get_node_by_uuid(const char *target_uuid)
return node;
}
+const char *
+get_node_ical_uuid(const struct tree_node *node)
+{
+ struct journal_entry *entry = node->data;
+ if (entry) {
+ return icalcomponent_get_uid(entry->component);
+ }
+ return NULL;
+}
bool
is_root_node(const struct tree_node *node)
{
@@ -1312,8 +1321,6 @@ update_or_create_fuse_entry_from_original(const char *filepath_original)
if (load_journal_entry_from_ics_file(filename_original,
updated_entry) != 0) {
- // Parsing failed, clean up and maybe remove old entry
- // if any
LOG("PARSING FAILED");
return;
}
@@ -1340,8 +1347,18 @@ update_or_create_fuse_entry_from_original(const char *filepath_original)
LOG("Has parent");
struct tree_node *parent = get_node_by_uuid(parent_uid);
if (parent) {
- move_node(new_or_updated_node->parent, parent,
- new_or_updated_node);
+ struct tree_node *current_parent =
+ new_or_updated_node->parent;
+
+ if (current_parent != NULL &&
+ strcmp(get_node_ical_uuid(current_parent),
+ get_node_ical_uuid(parent)) == 0) {
+ LOG("Already set, not moving");
+ }
+ else {
+ move_node(new_or_updated_node->parent, parent,
+ new_or_updated_node);
+ }
}
else {
LOG("Parent not found, adding to root");
@@ -1424,7 +1441,7 @@ delete_from_fuse_path(const char *filepath)
}
int
-update_delete_from_original_path(const char *filepath)
+delete_from_original_path(const char *filepath)
{
// Strip path, validate just the new basename
const char *keyname = strrchr(filepath, '/');
diff --git a/journal_entry.h b/journal_entry.h
@@ -100,7 +100,7 @@ delete_from_fuse_path(const char *filepath);
int
create_entry_from_fuse(const char *filename);
int
-update_delete_from_original_path(const char *filepath);
+delete_from_original_path(const char *filepath);
// Returns -1 on failure, 0 on success
int
diff --git a/main.c b/main.c
@@ -552,7 +552,7 @@ watch_ics_dir(void *arg)
}
size_t i = 0;
- while (i < (size_t)length) {
+ while (i < length) {
struct inotify_event *event =
(struct inotify_event *)&buffer[i];
@@ -565,26 +565,19 @@ watch_ics_dir(void *arg)
if (event->mask & IN_DELETE) {
pthread_mutex_lock(&entries_mutex);
- update_delete_from_original_path(
- full_path);
+ delete_from_original_path(full_path);
pthread_mutex_unlock(&entries_mutex);
}
else if (event->mask & IN_MODIFY) {
pthread_mutex_lock(&entries_mutex);
-
- // Reload entries on any change
update_or_create_fuse_entry_from_original(
full_path);
-
pthread_mutex_unlock(&entries_mutex);
}
else if (event->mask & IN_CREATE) {
pthread_mutex_lock(&entries_mutex);
-
- // Reload entries on any change
update_or_create_fuse_entry_from_original(
full_path);
-
pthread_mutex_unlock(&entries_mutex);
}
}
@@ -661,7 +654,6 @@ agendafs_opt_proc(void *data, const char *arg, int key,
exit(1);
case KEY_VERSION:
-
LOG("Is KEY_VERSION");
fprintf(stderr, "agendafs version %s\n", "v0.01 ALPHA");
fuse_opt_add_arg(outargs, "--version");