コード例 #1
0
} END_TEST

START_TEST (test_2) {
    object *obj = object_list();
    
    fail_unless(object_list_length(obj) == 0, NULL);
    
    object *val;
    val = object_int(1);
    object_list_insert_at(obj, 0, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 1, NULL);
    
    val = object_int(3);
    object_list_insert_at(obj, 1, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 2, NULL);
    
    val = object_int(2);
    object_list_insert_at(obj, 1, val);
    object_free(val);
    
    fail_unless(object_list_length(obj) == 3, NULL);
    
    object *next = object_copy(obj);
    
    fail_unless(object_list_length(next) == 3, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 2, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 1, NULL);
    
    object_list_remove(obj, 0);
    fail_unless(object_list_length(obj) == 0, NULL);
    object_free(obj);
    
    obj = next;
    next = object_copy(next);
    
    object_list_remove(obj, 1);
    fail_unless(object_list_length(obj) == 2, NULL);
    object_free(obj);
    
    obj = next;
    
    object_list_remove(obj, 2);
    fail_unless(object_list_length(obj) == 2, NULL);
    object_free(obj);
    
    object_free(obj);
} END_TEST
コード例 #2
0
ファイル: sendcommit-proc.c プロジェクト: airbai/seafile
static int
send_commit_start (CcnetProcessor *processor, int argc, char **argv)
{
    GString *buf;
    int ret;
    TransferTask *task = ((SeafileSendcommitProc *)processor)->tx_task;
    
    ObjectList *ol = object_list_new ();
    ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
                                                    task->head,
                                                    commit_collector,
                                                    ol, FALSE);
    if (ret == FALSE) {
        object_list_free (ol);
        seaf_warning ("[sendcommit] Load commits error\n");
        ccnet_processor_done (processor, FALSE);
        return -1;
    }
    g_return_val_if_fail (object_list_length(ol) != 0, -1);
    task->commits = ol;

    /* Send to_branch to the relay. */
    buf = g_string_new (NULL);
    g_string_printf (buf, "remote %s seafile-recvcommit %s %s",
                     processor->peer_id, task->to_branch, task->session_token);
    ccnet_processor_send_request (processor, buf->str);
    g_string_free (buf, TRUE);

    processor->state = INIT;

    return 0;
}
コード例 #3
0
ファイル: sendcommit-proc.c プロジェクト: airbai/seafile
static void
send_commit_ids (CcnetProcessor *processor)
{
    SeafileSendcommitProc *proc = (SeafileSendcommitProc *)processor;
    char buf[2048];
    char *ptr = buf;
    int i, count = 0;
    ObjectList *ol = proc->tx_task->commits;
    int ollen = object_list_length (ol);

    for (i = 0; i < ollen; i++) {
        memcpy (ptr, g_ptr_array_index(ol->obj_ids, i), 40);
        ptr += 40;
        *ptr++ = '\n';

        if (++count == 48) {
            *ptr = '\0';
            ccnet_processor_send_update (processor, SC_COMMIT_IDS, 
                                         SS_COMMIT_IDS, buf, 41 * count + 1);
            ptr = buf;
            count = 0;
        }
    }

    if (count) {
        *ptr = '\0';
        ccnet_processor_send_update (processor, SC_COMMIT_IDS, 
                                     SS_COMMIT_IDS, buf, 41 * count + 1);
    }

    object_list_free (ol);
    ccnet_processor_send_update (processor, SC_END, SS_END, NULL, 0);

    processor->state = SEND_OBJECT;
}
コード例 #4
0
ファイル: sendfs-proc.c プロジェクト: 2bj/seafile
static void
send_fs_roots (CcnetProcessor *processor)
{
    SeafileSendfsProc *proc = (SeafileSendfsProc *)processor;
    char buf[2096];
    char *ptr = buf;
    int i, count = 0;
    ObjectList *ol = proc->tx_task->fs_roots;
    int ollen = object_list_length (ol);

    if (proc->last_idx == ollen) {
        ccnet_processor_send_update (processor, SC_ROOT_END, SS_ROOT_END,
                                     NULL, 0);
        processor->state = SEND_OBJECT;
        return;
    }

    for (i = proc->last_idx; i < ollen; i++) {
        memcpy (ptr, g_ptr_array_index(ol->obj_ids, i), 40);
        ptr += 40;
        *ptr++ = '\n';
        
        if (++count == 48)
            break;
    }

    ccnet_processor_send_update (processor, SC_ROOT, SS_ROOT,
                                 buf, 41 * count);
    proc->last_idx = i;
}
コード例 #5
0
ファイル: putcommit-proc.c プロジェクト: Jack-Tsue/seafile
static int
send_commit_ids (CcnetProcessor *processor, const char *head)
{
    char buf[2048];
    char *ptr = buf;
    int i, count = 0;
    int ret;
    
    ObjectList *ol = object_list_new ();
    ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
                                                    head,
                                                    commit_collector,
                                                    ol);
    if (ret == FALSE) {
        object_list_free (ol);
        g_warning ("[putcommit] Load commits error\n");
        ccnet_processor_send_response (
            processor, SC_NOT_FOUND, SS_NOT_FOUND, NULL, 0);
        ccnet_processor_done (processor, FALSE);
        return -1;
    }

    int ollen = object_list_length(ol);
    g_assert (ollen != 0);

    for (i = 0; i < ollen; i++) {
        memcpy (ptr, g_ptr_array_index(ol->obj_ids, i), 40);
        ptr += 40;
        *ptr++ = '\n';

        if (++count == 48) {
            *ptr = '\0';
            g_debug ("[putcommit] Send commit ids:\n%s", buf);
            ccnet_processor_send_response (processor, SC_COMMIT_IDS, 
                                           SS_COMMIT_IDS, buf, 41 * count + 1);
            ptr = buf;
            count = 0;
        }
    }

    if (count) {
        *ptr = '\0';
        g_debug ("[putcommit] Send commit ids:\n%s", buf);
        ccnet_processor_send_response (processor, SC_COMMIT_IDS, 
                                       SS_COMMIT_IDS, buf, 41 * count + 1);
    }

    g_debug ("[putcommit] Sent commit ids.\n");
    ccnet_processor_send_response (processor, SC_END, SS_END, NULL, 0);

    return 0;
}
コード例 #6
0
ファイル: getfs-proc.c プロジェクト: AzinmarErus/seafile
static void
load_fsroot_list (CcnetProcessor *processor)
{
    USE_PRIV;
    SeafileGetfsProc *proc = (SeafileGetfsProc *) processor;
    ObjectList *ol = proc->tx_task->fs_roots;
    int i;
    int ollen = object_list_length (ol);

    for (i = 0; i < ollen; i++) {
        g_queue_push_tail (priv->inspect_queue,
                           g_strdup(g_ptr_array_index(ol->obj_ids, i)));
    }
}