/*! @brief Reset all databases of a group (anchor, hashtable and archive) * * @param group The group * @param error Pointer to an error struct * @returns TRUE on success, FALSE otherwise * */ osync_bool osync_group_reset(OSyncGroup *group, OSyncError **error) { OSyncDB *db = NULL; GList *m = NULL; char *path = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, group, error); osync_assert(group); /* Loop over all members... */ for (m = group->members; m; m = m->next) { OSyncMember *member = m->data; /* flush hashtable */ path = g_strdup_printf("%s%chashtable.db", osync_member_get_configdir(member), G_DIR_SEPARATOR); if (!(db = osync_db_new(error))) goto error_and_free; if (!osync_db_open(db, path, error)) goto error_and_free; osync_db_reset_full(db, error); g_free(path); /* flush anchor db */ path = g_strdup_printf("%s%canchor.db", osync_member_get_configdir(member), G_DIR_SEPARATOR); if (!(db = osync_db_new(error))) goto error_and_free; if (!osync_db_open(db, path, error)) goto error_and_free; osync_db_reset_full(db, error); g_free(path); } path = g_strdup_printf("%s%carchive.db", osync_group_get_configdir(group), G_DIR_SEPARATOR); if (!(db = osync_db_new(error))) goto error_and_free; if (!osync_db_open(db, path, error)) goto error_and_free; osync_db_reset_full(db, error); g_free(path); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error_and_free: g_free(path); //error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; }
/*! @brief Appends a member to the group * * Appends a member to the group * * @param group The group to which to append * @param member The member to append * */ void osync_group_add_member(OSyncGroup *group, OSyncMember *member) { g_assert(group); if (!osync_member_get_configdir(member)) { char *configdir = g_strdup_printf("%s%c%lli", group->configdir, G_DIR_SEPARATOR, _osync_group_create_member_id(group)); osync_member_set_configdir(member, configdir); g_free(configdir); } group->members = g_list_append(group->members, member); osync_member_ref(member); }
static void dump_hash(OSyncGroupEnv *env, const char *objtype, const char *groupname, char *memberid) { OSyncGroup *group = osync_group_env_find_group(env, groupname); #if 0 /* Unused */ OSyncError *error = NULL; long long int id = 0; OSyncMember *member = NULL; char *path = NULL; OSyncHashTable *table = NULL; #endif if (!group) { printf("Unable to find group with name \"%s\"\n", groupname); return; } printf("Dumping hashtable is currently not implemented!\n"); return; /* FIXME: public interface osync_hashltable_new() is gone! * no interface to access the disk directly! * */ #if 0 id = atoi(memberid); member = osync_group_find_member(group, id); if (!member) { printf("Unable to find member with id %s\n", memberid); return; } path = g_strdup_printf("%s/hashtable.db", osync_member_get_configdir(member)); table = osync_hashtable_new(path, objtype, &error); if (!table) goto error; g_free(path); if (!osync_hashtable_load(table, &error)) goto error; osync_hashtable_foreach(table, print_hashtable, NULL); osync_hashtable_unref(table); error: printf("ERROR: %s", osync_error_print(&error)); osync_error_unref(&error); #endif }
static void dump_hash(OSyncGroupEnv *env, const char *objtype, const char *groupname, char *memberid) { OSyncError *error = NULL; OSyncGroup *group = osync_group_env_find_group(env, groupname); long long int id = 0; OSyncMember *member = NULL; char *path = NULL; OSyncHashTable *table = NULL; if (!group) { printf("Unable to find group with name \"%s\"\n", groupname); return; } id = atoi(memberid); member = osync_group_find_member(group, id); if (!member) { printf("Unable to find member with id %s\n", memberid); return; } path = g_strdup_printf("%s/hashtable.db", osync_member_get_configdir(member)); table = osync_hashtable_new(path, objtype, &error); if (!table) goto error; g_free(path); osync_hashtable_foreach(table, print_hashtable, NULL); osync_hashtable_unref(table); return; error: printf("ERROR: %s", osync_error_print(&error)); osync_error_unref(&error); }