Lines Matching refs:node
86 const struct dsync_mailbox_node *node,
94 name = dsync_mailbox_node_get_full_name(ctx->local_tree, node);
98 change->ns = node->ns;
104 const struct dsync_mailbox_node *node, const char *name)
112 change->ns = node->ns;
114 memcpy(change->mailbox_guid, node->mailbox_guid,
116 change->uid_validity = node->uid_validity;
138 struct dsync_mailbox_node *node)
144 guid_p = node->mailbox_guid;
147 node->existence = DSYNC_MAILBOX_NODE_DELETED;
148 memset(node->mailbox_guid, 0, sizeof(node->mailbox_guid));
149 node->uid_validity = 0;
155 struct dsync_mailbox_node *node, const char *reason)
164 dsync_mailbox_node_get_full_name(tree, node),
165 guid_128_to_string(node->mailbox_guid), reason);
169 node->existence != DSYNC_MAILBOX_NODE_DELETED) {
174 change->ns = node->ns;
175 name = dsync_mailbox_node_get_full_name(tree, node);
177 memcpy(change->mailbox_guid, node->mailbox_guid,
180 sync_set_node_deleted(tree, node);
186 struct dsync_mailbox_node *node, const char *reason)
194 guid_p = node->mailbox_guid;
201 sync_delete_mailbox_node(ctx, tree, node, reason);
210 struct dsync_mailbox_node *node, *parent = NULL;
216 while (dsync_mailbox_tree_bfs_iter_next(iter, &node)) {
217 if (node->parent != parent) {
220 parent = node->parent;
222 if (node->existence == DSYNC_MAILBOX_NODE_DELETED &&
223 !dsync_mailbox_node_is_dir(node)) {
227 sync_delete_mailbox(ctx, tree, node,
230 /* treat the node as if it didn't exist. it'll
236 sync_set_node_deleted(tree, node);
240 array_append(&siblings, &node, 1);
259 dsync_mailbox_tree_node_attach_sorted(struct dsync_mailbox_node *node,
264 node->parent = parent;
266 if (dsync_mailbox_node_name_cmp(p, &node) > 0)
269 node->next = *p;
270 *p = node;
274 dsync_mailbox_tree_node_move_sorted(struct dsync_mailbox_node *node,
278 dsync_mailbox_tree_node_detach(node);
280 dsync_mailbox_tree_node_attach_sorted(node, parent);
286 struct dsync_mailbox_node *node, *parent, *ret;
288 node = ret = dsync_mailbox_tree_get(tree, name);
289 while (node->parent != NULL &&
290 node->existence == DSYNC_MAILBOX_NODE_NONEXISTENT) {
291 parent = node->parent;
292 dsync_mailbox_tree_node_detach(node);
293 dsync_mailbox_tree_node_attach_sorted(node, parent);
294 node = parent;
305 struct dsync_mailbox_node *node;
307 node = p_new(tree->pool, struct dsync_mailbox_node, 1);
308 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT;
309 node->name = p_strdup(tree->pool, src->name);
310 node->sync_temporary_name = src->sync_temporary_name;
311 node->ns = src->ns;
312 node->parent = parent;
313 node->next = *pos;
314 *pos = node;
315 return node;
334 struct dsync_mailbox_node *node;
336 for (node = parent->first_child; node != NULL; node = node->next) {
337 if (strcmp(node->name, name) == 0)
344 node_has_existent_children(struct dsync_mailbox_node *node, bool dirs_ok)
346 for (node = node->first_child; node != NULL; node = node->next) {
347 if (node->existence == DSYNC_MAILBOX_NODE_EXISTS &&
348 (dirs_ok || !dsync_mailbox_node_is_dir(node)))
350 if (node_has_existent_children(node, dirs_ok))
356 static bool node_is_existent(struct dsync_mailbox_node *node)
358 if (node->existence == DSYNC_MAILBOX_NODE_EXISTS)
360 return node_has_existent_children(node, TRUE);
364 struct dsync_mailbox_node *node)
367 size_t prefix_len = node->ns == NULL ? 0 : node->ns->prefix_len;
369 if (strcmp(node->name, "INBOX") == 0 && node->parent == &tree->root)
375 full_name = dsync_mailbox_node_get_full_name(tree, node);
376 if (node->ns->prefix[prefix_len-1] == mail_namespace_get_sep(node->ns))
378 return strncmp(full_name, node->ns->prefix, prefix_len) == 0 &&
385 struct dsync_mailbox_node *node,
396 i_assert(!sync_node_is_namespace_prefix(tree, node));
400 if (node->sync_temporary_name) {
403 p = strrchr(node->name, '-');
405 if (max_prefix_len > (size_t)(p - node->name))
406 max_prefix_len = p - node->name;
408 str_append_n(&buf, node->name, max_prefix_len);
417 } while (node_has_child(node->parent, str_c(&buf)));
420 dsync_mailbox_node_get_full_name(tree, node);
422 *reason_r = t_strdup_printf("Renamed '%s' to '%s'", node->name, str_c(&buf));
423 node->name = p_strdup(tree->pool, str_c(&buf));
424 node->sync_temporary_name = TRUE;
425 node->last_renamed_or_created = 0;
426 dsync_mailbox_tree_node_move_sorted(node, new_parent);
428 if (tree == ctx->local_tree && node_is_existent(node)) {
430 new_name = dsync_mailbox_node_get_full_name(tree, node);
436 change->ns = node->ns;
442 static bool node_has_parent(struct dsync_mailbox_node *node,
445 for (; node != NULL; node = node->parent) {
446 if (node == parent)
456 struct dsync_mailbox_node *node,
465 i_assert(node != NULL);
468 /* move/rename node in the tree, so that its position/name is identical
470 temporary name (i.e. it assumes that node's name becomes temp_node's
477 if (node_has_parent(parent, node)) {
478 /* don't introduce a loop. temporarily rename node
480 sync_rename_node_to_temp(ctx, tree, node, &tree->root, reason_r);
487 name = dsync_mailbox_node_get_full_name(tree, node);
492 node->name = p_strdup(tree->pool, other_node->name);
493 node->sync_temporary_name = other_node->sync_temporary_name;
494 node->last_renamed_or_created = other_node->last_renamed_or_created;
495 /* change node's parent if necessary. in any case detach+reattach it
496 sorted, because the nodes must be sorted by name, and the node's
498 dsync_mailbox_tree_node_move_sorted(node, parent);
500 if (tree == ctx->local_tree && node_is_existent(node)) {
508 change->ns = node->ns;
596 struct dsync_mailbox_node *node)
598 if (node == NULL)
600 if (node == &tree->root)
602 return sync_node_is_namespace_prefix(tree, node);
621 at all. Note that node1 and node2 may be the same node pointers. */
651 renames where the destination parent is the current node's
802 struct dsync_mailbox_node *node, *other_node;
805 for (node = dir_node->first_child; node != NULL; node = node->next) {
806 if (dsync_mailbox_node_is_dir(node)) {
807 other_node = sync_find_branch(tree, other_tree, node);
811 guid_p = node->mailbox_guid;
870 /* add a missing local node */
876 /* add a missing remote node */
930 static bool mailbox_node_hash_first_child(struct dsync_mailbox_node *node,
933 for (node = node->first_child; node != NULL; node = node->next) {
934 if (node->existence == DSYNC_MAILBOX_NODE_EXISTS) {
935 md5_update(md5, node->mailbox_guid,
936 sizeof(node->mailbox_guid));
937 md5_update(md5, node->name, strlen(node->name));
940 if (node->first_child != NULL) {
941 if (mailbox_node_hash_first_child(node, md5))
949 mailbox_node_generate_suffix(struct dsync_mailbox_node *node)
954 if (!dsync_mailbox_node_is_dir(node))
955 return guid_128_to_string(node->mailbox_guid);
958 if (!mailbox_node_hash_first_child(node, &md5))
987 struct dsync_mailbox_node *node,
999 new_suffix = mailbox_node_generate_suffix(node);
1001 p = strrchr(node->name, '-');
1005 if (max_prefix_len > (size_t)(p-node->name))
1006 max_prefix_len = p-node->name;
1007 str_append_n(str, node->name, max_prefix_len);
1009 while (node_has_child(node->parent, str_c(str)))
1013 dsync_mailbox_node_get_full_name(tree, node), str_c(str));
1014 node->name = p_strdup(tree->pool, str_c(str));
1016 dsync_mailbox_tree_node_move_sorted(node, node->parent);
1017 node->sync_temporary_name = FALSE;
1023 struct dsync_mailbox_node *node)
1027 for (child = node->first_child; child != NULL; child = child->next)
1032 node->existence != DSYNC_MAILBOX_NODE_NONEXISTENT) {
1033 sync_add_dir_change(ctx, node,
1036 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT;
1037 node->sync_temporary_name = FALSE;
1043 struct dsync_mailbox_node *node, bool *renames_r)
1047 for (; node != NULL; node = node->next) {
1048 while (sync_rename_temp_mailboxes(ctx, tree, node->first_child, renames_r)) ;
1050 if (!node->sync_temporary_name) {
1051 } else if (dsync_mailbox_node_is_dir(node) &&
1052 (node->first_child == NULL ||
1053 !node_has_existent_children(node, FALSE))) {
1060 dsync_mailbox_node_get_full_name(tree, node));
1062 sync_rename_delete_node_dirs(ctx, tree, node);
1066 sync_rename_temp_mailbox_node(tree, node, &reason);
1071 dsync_mailbox_node_get_full_name(tree, node), reason);
1112 static bool sync_is_wrong_mailbox(struct dsync_mailbox_node *node,
1121 if (node->uid_validity != wanted_node->uid_validity) {
1124 node->uid_validity);
1127 if (node->uid_next > wanted_node->uid_next) {
1130 node->uid_next,
1134 if (memcmp(node->mailbox_guid, wanted_node->mailbox_guid,
1135 sizeof(node->mailbox_guid)) != 0) {
1146 struct dsync_mailbox_node *node,
1152 while (node != NULL && wanted_node != NULL) {
1153 if (node->first_child != NULL) {
1156 node->first_child, wanted_node->first_child);
1158 ret = strcmp(node->name, wanted_node->name);
1160 /* node shouldn't exist */
1161 if (node->existence == DSYNC_MAILBOX_NODE_EXISTS &&
1162 !dsync_mailbox_node_is_dir(node)) {
1163 sync_delete_mailbox_node(ctx, tree, node,
1166 node = node->next;
1171 if (sync_is_wrong_mailbox(node, wanted_node, &reason) &&
1172 node->existence == DSYNC_MAILBOX_NODE_EXISTS &&
1173 !dsync_mailbox_node_is_dir(node))
1174 sync_delete_mailbox_node(ctx, tree, node, reason);
1175 node = node->next;
1179 for (; node != NULL; node = node->next) {
1180 /* node and its children shouldn't exist */
1181 if (node->first_child != NULL) {
1184 node->first_child, NULL);
1186 if (node->existence == DSYNC_MAILBOX_NODE_EXISTS &&
1187 !dsync_mailbox_node_is_dir(node))
1188 sync_delete_mailbox_node(ctx, tree, node, "Mailbox doesn't exist");
1207 struct dsync_mailbox_node *node, *other_node;
1215 while (dsync_mailbox_tree_iter_next(iter, &name, &node)) {
1217 i_assert(!node->sync_temporary_name);
1218 if (dsync_mailbox_node_is_dir(node))
1221 i_assert(node->existence == DSYNC_MAILBOX_NODE_EXISTS);
1223 guid_p = node->mailbox_guid;
1230 other_node->ns = node->ns;
1231 other_node->uid_validity = node->uid_validity;
1232 memcpy(other_node->mailbox_guid, node->mailbox_guid,
1236 } else if (!guid_128_equals(node->mailbox_guid,
1244 i_assert(node->existence == DSYNC_MAILBOX_NODE_EXISTS);
1245 i_assert(node->ns == other_node->ns);
1248 sync_add_create_change(ctx, node, name);
1252 i_assert(node->existence == DSYNC_MAILBOX_NODE_EXISTS);
1253 i_assert(node->ns == other_node->ns);
1379 dsync_mailbox_tree_update_child_timestamps(struct dsync_mailbox_node *node,
1384 if (node->last_renamed_or_created < parent_timestamp)
1385 node->last_renamed_or_created = parent_timestamp;
1386 ts = node->last_renamed_or_created;
1388 for (node = node->first_child; node != NULL; node = node->next)
1389 dsync_mailbox_tree_update_child_timestamps(node, ts);