Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 8578)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2008-03-21  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #329571
+
+	* backends/file/e-cal-backend-file.c:
+	(e_cal_backend_file_modify_object):
+	Preserve detached instances when modifying master object.
+
 2008-03-05  Jens Granseuer  <jensgr@gmx.net>
 
 	** Fixes bug #520362
Index: calendar/backends/file/e-cal-backend-file.c
===================================================================
--- calendar/backends/file/e-cal-backend-file.c	(revision 8578)
+++ calendar/backends/file/e-cal-backend-file.c	(working copy)
@@ -1908,6 +1908,7 @@ e_cal_backend_file_modify_object (ECalBa
 	ECalComponent *comp, *recurrence;
 	ECalBackendFileObject *obj_data;
 	struct icaltimetype current;
+	GList *detached = NULL;
 
 	cbfile = E_CAL_BACKEND_FILE (backend);
 	priv = cbfile->priv;
@@ -2117,10 +2118,39 @@ e_cal_backend_file_modify_object (ECalBa
 		if (old_object)
 			*old_object = e_cal_component_get_as_string (obj_data->full_object);
 
+		if (obj_data->recurrences_list) {
+			/* has detached components, preserve them */
+			GList *l;
+
+			for (l = obj_data->recurrences_list; l; l = l->next) {
+				detached = g_list_prepend (detached, g_object_ref (l->data));
+			}
+		}
+
 		remove_component (cbfile, comp_uid, obj_data);
 
 		/* Add the new object */
 		add_component (cbfile, comp, TRUE);
+
+		if (detached) {
+			/* it had some detached components, place them back */
+			comp_uid = icalcomponent_get_uid (e_cal_component_get_icalcomponent (comp));
+
+			if ((obj_data = g_hash_table_lookup (priv->comp_uid_hash, comp_uid)) != NULL) {
+				GList *l;
+
+				for (l = detached; l; l = l->next) {
+					ECalComponent *c = l->data;
+
+					g_hash_table_insert (obj_data->recurrences, e_cal_component_get_recurid_as_string (c), c);
+					icalcomponent_add_component (priv->icalcomp, e_cal_component_get_icalcomponent (c));
+					priv->comp = g_list_append (priv->comp, c);
+					obj_data->recurrences_list = g_list_append (obj_data->recurrences_list, c);
+				}
+			}
+
+			g_list_free (detached);
+		}
 		break;
 	}
 
