コード例 #1
0
ファイル: vc-utils.c プロジェクト: 2bj/seafile
int
compare_file_content (const char *path, struct stat *st, const unsigned char *ce_sha1,
                      SeafileCrypt *crypt)
{
    CDCFileDescriptor cdc;
    unsigned char sha1[20];

    memset (&cdc, 0, sizeof(cdc));
    cdc.block_sz = calculate_chunk_size (st->st_size);
    cdc.block_min_sz = cdc.block_sz >> 2;
    cdc.block_max_sz = cdc.block_sz << 2;
    cdc.write_block = seafile_write_chunk;
    if (filename_chunk_cdc (path, &cdc, crypt, FALSE) < 0) {
        g_warning ("Failed to chunk file.\n");
        return -1;
    }
    memcpy (sha1, cdc.file_sum, 20);

    char id1[41], id2[41];
    rawdata_to_hex (sha1, id1, 20);
    rawdata_to_hex (ce_sha1, id2, 20);
    printf ("id1: %s, id2: %s.\n", id1, id2);

    return hashcmp (sha1, ce_sha1);
}
コード例 #2
0
ファイル: vc-utils.c プロジェクト: Guilhem30/seafile
int
compare_file_content (const char *path, SeafStat *st, const unsigned char *ce_sha1,
                      SeafileCrypt *crypt, int repo_version)
{
    CDCFileDescriptor cdc;
    unsigned char sha1[20];

    if (st->st_size == 0) {
        memset (sha1, 0, 20);
    } else {
        memset (&cdc, 0, sizeof(cdc));
        cdc.block_sz = calculate_chunk_size (st->st_size);
        cdc.block_min_sz = cdc.block_sz >> 2;
        cdc.block_max_sz = cdc.block_sz << 2;
        cdc.write_block = seafile_write_chunk;
        if (filename_chunk_cdc (path, &cdc, crypt, FALSE) < 0) {
            g_warning ("Failed to chunk file.\n");
            return -1;
        }

        if (repo_version > 0)
            seaf_fs_manager_calculate_seafile_id_json (repo_version, &cdc, sha1);
        else
            memcpy (sha1, cdc.file_sum, 20);

        if (cdc.blk_sha1s)
            free (cdc.blk_sha1s);
    }

#if 0
    char id1[41], id2[41];
    rawdata_to_hex (sha1, id1, 20);
    rawdata_to_hex (ce_sha1, id2, 20);
    seaf_debug ("id1: %s, id2: %s.\n", id1, id2);
#endif

    return hashcmp (sha1, ce_sha1);
}