Fix the crash when creating an event
package / package (push) Successful in 1m50s

02975fa3 took the sequence commits out of the event's setters, so that
saving could raise SEQUENCE only once. But EDS won't clone a component
with a raise pending, and the editor clones a new event as it opens it,
so creating an event aborted in e_cal_component_clone().

The setters commit the sequence again, as before. A GcalEvent now keeps
the SEQUENCE it was loaded with, and its clones carry it along, so
gcal_event_prepare_to_save() still raises an updated event's SEQUENCE
by one at most, and starts a new event at 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 09:52:50 -07:00
co-authored by Claude Opus 5.5
parent 02975fa3f5
commit ef57279413
4 changed files with 71 additions and 13 deletions
+42 -12
View File
@@ -107,6 +107,14 @@ struct _GcalEvent
GcalCalendar *calendar; GcalCalendar *calendar;
GcalRecurrence *recurrence; GcalRecurrence *recurrence;
/*
* The SEQUENCE of the event as it was loaded. The setters raise the
* component's SEQUENCE for every significant change, because EDS won't
* clone a component with a raise pending, so this is what saving counts
* from to raise it only once.
*/
gint loaded_sequence;
}; };
static void gcal_event_initable_iface_init (GInitableIface *iface); static void gcal_event_initable_iface_init (GInitableIface *iface);
@@ -467,6 +475,7 @@ gcal_event_set_component_internal (GcalEvent *self,
{ {
g_assert (self->component == NULL); g_assert (self->component == NULL);
self->component = e_cal_component_clone (component); self->component = e_cal_component_clone (component);
self->loaded_sequence = MAX (e_cal_component_get_sequence (self->component), 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPONENT]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMPONENT]);
} }
@@ -856,12 +865,20 @@ GcalEvent*
gcal_event_new_from_event (GcalEvent *self) gcal_event_new_from_event (GcalEvent *self)
{ {
g_autoptr (ECalComponent) component = NULL; g_autoptr (ECalComponent) component = NULL;
GcalEvent *event;
g_return_val_if_fail (GCAL_IS_EVENT (self), NULL); g_return_val_if_fail (GCAL_IS_EVENT (self), NULL);
component = e_cal_component_clone (self->component); component = e_cal_component_clone (self->component);
e_cal_component_commit_sequence (component);
return gcal_event_new (self->calendar, component, NULL); event = gcal_event_new (self->calendar, component, NULL);
/* The clone is an edit of the same saved event */
if (event)
event->loaded_sequence = self->loaded_sequence;
return event;
} }
/** /**
@@ -998,6 +1015,7 @@ gcal_event_set_date_end (GcalEvent *self,
component_dt = build_component_from_datetime (self, dt); component_dt = build_component_from_datetime (self, dt);
e_cal_component_set_dtend (self->component, component_dt); e_cal_component_set_dtend (self->component, component_dt);
e_cal_component_commit_sequence (self->component);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_END]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_END]);
@@ -1043,6 +1061,7 @@ gcal_event_set_date_start (GcalEvent *self,
component_dt = build_component_from_datetime (self, dt); component_dt = build_component_from_datetime (self, dt);
e_cal_component_set_dtstart (self->component, component_dt); e_cal_component_set_dtstart (self->component, component_dt);
e_cal_component_commit_sequence (self->component);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_START]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_START]);
@@ -1130,6 +1149,8 @@ gcal_event_set_description (GcalEvent *self,
e_cal_component_set_descriptions (self->component, NULL); e_cal_component_set_descriptions (self->component, NULL);
} }
e_cal_component_commit_sequence (self->component);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DESCRIPTION]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DESCRIPTION]);
} }
} }
@@ -1240,6 +1261,8 @@ gcal_event_remove_all_alarms (GcalEvent *self)
g_hash_table_iter_remove (&iter); g_hash_table_iter_remove (&iter);
} }
e_cal_component_commit_sequence (self->component);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -1284,6 +1307,8 @@ gcal_event_add_alarm (GcalEvent *self,
e_cal_component_alarm_free (new_alarm); e_cal_component_alarm_free (new_alarm);
e_cal_component_commit_sequence (self->component);
GCAL_EXIT; GCAL_EXIT;
} }
@@ -1314,6 +1339,7 @@ gcal_event_remove_alarm (GcalEvent *self,
g_hash_table_remove (self->alarms, GINT_TO_POINTER (type)); g_hash_table_remove (self->alarms, GINT_TO_POINTER (type));
e_cal_component_commit_sequence (self->component);
} }
} }
@@ -1354,6 +1380,7 @@ gcal_event_set_location (GcalEvent *self,
if (g_strcmp0 (current_location, location) != 0) if (g_strcmp0 (current_location, location) != 0)
{ {
e_cal_component_set_location (self->component, (location && *location) ? location : NULL); e_cal_component_set_location (self->component, (location && *location) ? location : NULL);
e_cal_component_commit_sequence (self->component);
g_clear_pointer (&self->location, g_free); g_clear_pointer (&self->location, g_free);
self->location = g_strdup (location ? location : ""); self->location = g_strdup (location ? location : "");
@@ -1456,6 +1483,7 @@ gcal_event_set_summary (GcalEvent *self,
text_component = e_cal_component_text_new (summary ? summary : "", NULL); text_component = e_cal_component_text_new (summary ? summary : "", NULL);
e_cal_component_set_summary (self->component, text_component); e_cal_component_set_summary (self->component, text_component);
e_cal_component_commit_sequence (self->component);
e_cal_component_text_free (text_component); e_cal_component_text_free (text_component);
@@ -1846,6 +1874,8 @@ gcal_event_set_recurrence (GcalEvent *self,
i_cal_component_add_property (icalcomp, prop); i_cal_component_add_property (icalcomp, prop);
} }
e_cal_component_commit_sequence (self->component);
g_clear_object (&rrule); g_clear_object (&rrule);
g_clear_object (&prop); g_clear_object (&prop);
} }
@@ -2031,6 +2061,7 @@ set_component_attendees (GcalEvent *self,
GSList *ecal_attendees) GSList *ecal_attendees)
{ {
e_cal_component_set_attendees (self->component, ecal_attendees); e_cal_component_set_attendees (self->component, ecal_attendees);
e_cal_component_commit_sequence (self->component);
g_list_store_remove_all (self->attendees); g_list_store_remove_all (self->attendees);
load_attendees (self); load_attendees (self);
@@ -2065,6 +2096,7 @@ gcal_event_set_organizer (GcalEvent *self,
} }
e_cal_component_set_organizer (self->component, organizer); e_cal_component_set_organizer (self->component, organizer);
e_cal_component_commit_sequence (self->component);
e_cal_component_organizer_free (organizer); e_cal_component_organizer_free (organizer);
} }
@@ -2445,9 +2477,10 @@ gcal_event_conferences_equal (GcalEvent *event1,
* them to the people invited, whose mail apps use them to tell an update * them to the people invited, whose mail apps use them to tell an update
* from an invitation they've already seen. * from an invitation they've already seen.
* *
* A new event starts at SEQUENCE 0. An updated one goes up by one if its * A new event starts at SEQUENCE 0. An updated one goes up by one from
* date, time or recurrence changed since it was loaded, however many times * the SEQUENCE it was loaded with if its date, time or recurrence changed,
* they were changed in the editor. DTSTAMP is the time of saving. * however many times they were changed in the editor. DTSTAMP is the time
* of saving.
*/ */
void void
gcal_event_prepare_to_save (GcalEvent *self, gcal_event_prepare_to_save (GcalEvent *self,
@@ -2457,15 +2490,12 @@ gcal_event_prepare_to_save (GcalEvent *self,
g_return_if_fail (GCAL_IS_EVENT (self)); g_return_if_fail (GCAL_IS_EVENT (self));
if (new_event)
{
e_cal_component_abort_sequence (self->component);
e_cal_component_set_sequence (self->component, 0);
}
else
{
e_cal_component_commit_sequence (self->component); e_cal_component_commit_sequence (self->component);
}
if (new_event)
e_cal_component_set_sequence (self->component, 0);
else if (e_cal_component_get_sequence (self->component) > self->loaded_sequence)
e_cal_component_set_sequence (self->component, self->loaded_sequence + 1);
now = i_cal_time_new_current_with_zone (i_cal_timezone_get_utc_timezone ()); now = i_cal_time_new_current_with_zone (i_cal_timezone_get_utc_timezone ());
e_cal_component_set_dtstamp (self->component, now); e_cal_component_set_dtstamp (self->component, now);
@@ -252,6 +252,7 @@ remove_recurrence_properties (GcalEvent *event)
e_cal_component_set_recurid (comp, NULL); e_cal_component_set_recurid (comp, NULL);
e_cal_component_set_rrules (comp, NULL); e_cal_component_set_rrules (comp, NULL);
e_cal_component_commit_sequence (comp);
} }
static void static void
+2
View File
@@ -352,6 +352,8 @@ gcal_util_build_component_from_details (const gchar *summary,
e_cal_component_set_summary (event, summ); e_cal_component_set_summary (event, summ);
e_cal_component_text_free (summ); e_cal_component_text_free (summ);
e_cal_component_commit_sequence (event);
return event; return event;
} }
+26 -1
View File
@@ -837,6 +837,9 @@ event_prepare_to_save (void)
g_autoptr (GcalEvent) edited = NULL; g_autoptr (GcalEvent) edited = NULL;
g_autoptr (GcalEvent) renamed = NULL; g_autoptr (GcalEvent) renamed = NULL;
g_autoptr (GcalEvent) created = NULL; g_autoptr (GcalEvent) created = NULL;
g_autoptr (GcalEvent) reclone = NULL;
g_autoptr (GcalEvent) unsequenced = NULL;
g_autoptr (GcalEvent) moved = NULL;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
gint64 before; gint64 before;
@@ -850,7 +853,6 @@ event_prepare_to_save (void)
move_event (edited, 1); move_event (edited, 1);
move_event (edited, 1); move_event (edited, 1);
move_event (edited, 1); move_event (edited, 1);
g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (edited)), ==, 3);
gcal_event_prepare_to_save (edited, FALSE); gcal_event_prepare_to_save (edited, FALSE);
g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (edited)), ==, 4); g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (edited)), ==, 4);
g_assert_cmpint (get_dtstamp_unix (edited), >=, before); g_assert_cmpint (get_dtstamp_unix (edited), >=, before);
@@ -869,6 +871,29 @@ event_prepare_to_save (void)
gcal_event_prepare_to_save (created, TRUE); gcal_event_prepare_to_save (created, TRUE);
g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (created)), ==, 0); g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (created)), ==, 0);
g_assert_cmpint (get_dtstamp_unix (created), >=, before); g_assert_cmpint (get_dtstamp_unix (created), >=, before);
/*
* An event can be cloned right after its time changed, as when the editor
* opens a new event; EDS refuses to clone one with a raise pending. And a
* clone of a clone still counts from the SEQUENCE that was loaded.
*/
g_clear_object (&edited);
edited = gcal_event_new_from_event (original);
move_event (edited, 1);
reclone = gcal_event_new_from_event (edited);
g_assert_nonnull (reclone);
move_event (reclone, 1);
gcal_event_prepare_to_save (reclone, FALSE);
g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (reclone)), ==, 4);
/* An event saved without a SEQUENCE has 0, so its first change makes 1 */
unsequenced = create_event_for_string (STUB_EVENT, &error);
g_assert_no_error (error);
moved = gcal_event_new_from_event (unsequenced);
move_event (moved, 1);
move_event (moved, 1);
gcal_event_prepare_to_save (moved, FALSE);
g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (moved)), ==, 1);
} }
/*********************************************************************************************************************/ /*********************************************************************************************************************/