agendafs

A filesystem for your calendar.

git clone git://mccd.space/agendafs
commit 99f3949de7762a465370655bbd6863d5bc2ed350
parent 8012839b00211d0472286e7cac293fea40d79f12
Author: Marc Coquand <marc@coquand.email>
Date:   Mon,  1 Sep 2025 18:40:33 +0200

Update class by setting rather than delete insert

Not sure why the first approach didn't work, but this one should.

Diffstat:
Mfuse_node.c | 40+++++++++++++---------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/fuse_node.c b/fuse_node.c
@@ -1,8 +1,8 @@
 #include "agenda_entry.h"
+#include "arena.h"
 #include "fuse_node_store.h"
 #include "hashmap.h"
 #include "ical_extra.h"
-#include "arena.h"
 #include "path.h"
 #include "tree.h"
 #include "util.h"
@@ -91,8 +91,7 @@ node_is_directory(arena *ar, const struct tree_node *node,
 }
 
 size_t
-write_ical_file(arena *ar, const struct tree_node *node,
-		icalcomponent *ic)
+write_ical_file(arena *ar, const struct tree_node *node, icalcomponent *ic)
 {
 
 	// Always set last modified to the time we write
@@ -138,8 +137,7 @@ get_icalcomponent_from_node(arena *ar, const struct tree_node *n)
 }
 
 int
-write_parent_child_components(arena *ar,
-			      const struct tree_node *parent,
+write_parent_child_components(arena *ar, const struct tree_node *parent,
 			      icalcomponent *iparent,
 			      const struct tree_node *child,
 			      icalcomponent *ichild)
@@ -151,8 +149,7 @@ write_parent_child_components(arena *ar,
 
 // Writes ics component summary to the filename of the tree_node
 int
-update_summary(arena *ar, icalcomponent *ics,
-	       const struct tree_node *node)
+update_summary(arena *ar, icalcomponent *ics, const struct tree_node *node)
 {
 	if (is_directory_component(ics)) {
 		icalcomponent_set_summary(ics, get_node_filename(node));
@@ -275,8 +272,7 @@ load_root_node_tree()
 		if (entry->d_type == DT_REG && strstr(entry->d_name, ".ics")) {
 			LOG("Loading %s", entry->d_name);
 			struct agenda_entry *new_entry =
-			    load_agenda_entry_from_ics_file(ar,
-							    entry->d_name);
+			    load_agenda_entry_from_ics_file(ar, entry->d_name);
 			if (new_entry) {
 				create_fuse_node(new_entry);
 				LOG("Inserted filename_vdir: %s, %s",
@@ -338,8 +334,7 @@ load_root_node_tree()
 
 // Sets a validated dtstart
 int
-set_dtstart(arena *ar, const char *dtstart_c,
-	    const struct tree_node *node)
+set_dtstart(arena *ar, const char *dtstart_c, const struct tree_node *node)
 {
 	struct icaltimetype dtstart = icaltime_from_string(dtstart_c);
 	if (icaltime_compare(dtstart, icaltime_null_time()) == 0) {
@@ -572,11 +567,7 @@ set_node_class(arena *ar, const struct tree_node *node,
 	icalproperty *classp =
 	    icalcomponent_get_first_property(inner, ICAL_CLASS_PROPERTY);
 
-	icalcomponent_remove_property(inner, classp);
-
-	icalproperty *new_class_prop = icalproperty_new_class(new_class);
-	icalcomponent_add_property(inner, new_class_prop);
-
+	icalproperty_set_class(classp, new_class);
 	return write_ical_file(ar, node, component);
 }
 
@@ -683,8 +674,7 @@ insert_fuse_node_to_path(arena *ar, const char *fuse_path,
 enum ENTRY_TYPE { ENTRY_DIRECTORY, ENTRY_FILE };
 
 int
-create_entry_from_fuse(arena *ar, const char *fuse_path,
-		       enum ENTRY_TYPE etype)
+create_entry_from_fuse(arena *ar, const char *fuse_path, enum ENTRY_TYPE etype)
 {
 	const char *entry_prefix = "/";
 	if (strncmp(fuse_path, entry_prefix, strlen(entry_prefix)) != 0) {
@@ -714,13 +704,11 @@ create_entry_from_fuse(arena *ar, const char *fuse_path,
 
 	struct tree_node *new_node = create_fuse_node(new_entry);
 
-	return insert_fuse_node_to_path(ar, fuse_path, new_node,
-					new_component);
+	return insert_fuse_node_to_path(ar, fuse_path, new_node, new_component);
 }
 
 int
-update_or_create_fuse_entry_from_vdir(arena *ar,
-				      const char *filepath_vdir)
+update_or_create_fuse_entry_from_vdir(arena *ar, const char *filepath_vdir)
 {
 	const char *filename_vdir = get_filename(filepath_vdir);
 	LOG("Filename original is %s", filename_vdir);
@@ -780,8 +768,7 @@ do_agenda_rename(arena *ar, const char *old, const char *new)
 	struct tree_node *child_node = get_node_by_path(ar, old);
 	assert(child_node);
 
-	icalcomponent *child_ics =
-	    get_icalcomponent_from_node(ar, child_node);
+	icalcomponent *child_ics = get_icalcomponent_from_node(ar, child_node);
 	assert(child_ics);
 
 	icalcomponent *new_parent_ics =
@@ -802,9 +789,8 @@ do_agenda_rename(arena *ar, const char *old, const char *new)
 
 	if (new_parent_ics) {
 		move_node(new_parent_node, child_node);
-		write_parent_child_components(ar, new_parent_node,
-					      new_parent_ics, child_node,
-					      child_ics);
+		write_parent_child_components(
+		    ar, new_parent_node, new_parent_ics, child_node, child_ics);
 	}
 	else {
 		move_node(fuse_root, child_node);