diff options
Diffstat (limited to 'c_implementation')
-rw-r--r-- | c_implementation/include/libakfs.h | 2 | ||||
-rw-r--r-- | c_implementation/src/ak_fs.c | 17 | ||||
-rw-r--r-- | c_implementation/src/ak_fs_main.c | 3 | ||||
-rw-r--r-- | c_implementation/tests/test_akfs.c | 54 |
4 files changed, 45 insertions, 31 deletions
diff --git a/c_implementation/include/libakfs.h b/c_implementation/include/libakfs.h index f223c28..3eb0ba3 100644 --- a/c_implementation/include/libakfs.h +++ b/c_implementation/include/libakfs.h @@ -421,7 +421,7 @@ bool ak_fs_mt_branch_compare(mt_branch*, mt_branch*); * @param sha512sum* * @return int status */ -int ak_fs_cat_file_from_root_hash(sha512sum*); +int ak_fs_cat_file_from_root_hash(const sha512sum*); /** * Concatenates a file from a akfs_map_v3 map diff --git a/c_implementation/src/ak_fs.c b/c_implementation/src/ak_fs.c index 07178bc..8ede3f6 100644 --- a/c_implementation/src/ak_fs.c +++ b/c_implementation/src/ak_fs.c @@ -279,7 +279,7 @@ int ak_fs_ls() return 0; } -int ak_fs_cat_file_from_root_hash(sha512sum* rh) +int ak_fs_cat_file_from_root_hash(const sha512sum* rh) { const char* chunks_dir = getenv("AK_CHUNKSDIR"); if ( chunks_dir == NULL ) @@ -296,7 +296,9 @@ int ak_fs_cat_file_from_root_hash(sha512sum* rh) FILE *fd; char *fullpath; bool is_chunk = false; - if ( asprintf(&fullpath, "%s/%s", leafs_dir, ak_fs_sha512sum_struct_read_as_string(rh)) == -1 ) return -1; + char root_hash_str[129] = {0}; + ak_fs_sha512sum_struct_to_string(rh, root_hash_str); + if ( asprintf(&fullpath, "%s/%s", leafs_dir, root_hash_str) == -1 ) return -1; fd = fopen(fullpath, "r"); if ( fd == NULL ) { @@ -370,7 +372,12 @@ int ak_fs_cfm(akfs_map_v3* map) { sha512sum x; ak_fs_sha512sum_init(&x); - x = *(ak_fs_map_v3_get_root_hash(map)); - ak_fs_cat_file_from_root_hash(&x); - return 0; + const sha512sum *rh_ptr = ak_fs_map_v3_get_root_hash(map); + if ( rh_ptr == NULL ) + { + ak_log_debug(__func__, "No root hash found on the map"); + return -1; + } + x = *rh_ptr; + return ak_fs_cat_file_from_root_hash(&x); } diff --git a/c_implementation/src/ak_fs_main.c b/c_implementation/src/ak_fs_main.c index b25e308..e399544 100644 --- a/c_implementation/src/ak_fs_main.c +++ b/c_implementation/src/ak_fs_main.c @@ -6,7 +6,8 @@ static int ak_fs_usage() { ak_log_debug(__func__, "Available commands:"); - ak_log_debug(__func__, "ak fs --list"); + ak_log_debug(__func__, "akfs --list"); + ak_log_debug(__func__, "akfs --cfm <map hash>"); return 1; } diff --git a/c_implementation/tests/test_akfs.c b/c_implementation/tests/test_akfs.c index 247a59a..d08ea3b 100644 --- a/c_implementation/tests/test_akfs.c +++ b/c_implementation/tests/test_akfs.c @@ -17,11 +17,11 @@ static void test_correct_string_correct_length() // printf("Hash returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) == 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -38,11 +38,11 @@ static void test_bad_string_correct_length() // printf("Hash returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -59,11 +59,11 @@ static void test_less_than_length() // printf("Hash returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -80,11 +80,11 @@ static void test_more_than_length() // printf("Hash returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -101,11 +101,11 @@ static void test_string_is_empty() // printf("Hash returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -118,11 +118,11 @@ static void test_hash_path_test() // printf("Path returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -135,11 +135,11 @@ static void test_hash_dir_test() // printf("Path returned:\t%s\n", resulted_string); if ( strcmp(queried_string, resulted_string) != 0 ) { - ak_log_info(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_error(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -171,11 +171,11 @@ static void test_hash_save_to_file() ak_fs_sha512sum_struct_to_string(resulted_hash, resulted_string); if ( strcmp(queried_string, resulted_string) == 0 ) { - ak_log_debug(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_debug(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } fclose(fd); } @@ -189,11 +189,11 @@ static void test_hash_check() ak_fs_sha512sum_string_to_struct(queried_string, &b); if ( ak_fs_sha512sum_compare(&a,&b) ) { - ak_log_debug(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); } else { - ak_log_debug(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); } } @@ -205,7 +205,7 @@ static void test_map_opener() ak_fs_sha512sum_string_to_struct(map_string, &(map.mh)); if ( ak_fs_map_v3_open_from_file(&map) != 0 ) { - ak_log_debug(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); return; } const char *orig_string = "fa19bdc471bedc42abf3ff52069214bc7339a7eafc03f8551e8af892a0e3ce175cff0dde6f815da031cd0566fded455c937f7cae27181f7a90ab92e6131ba2be"; @@ -225,12 +225,12 @@ static void test_map_opener() (strcmp(root_string, ak_fs_sha512sum_struct_read_as_string(&(map.rh)))!=0) || (strcmp(filename, map.filename)!=0)) { - ak_log_debug(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); return; } else { - ak_log_debug(__func__, "PASSED"); + ak_log_test(__func__, "PASSED"); return; } } @@ -243,17 +243,23 @@ static void test_ak_fs_ls() static void test_ak_fs_cfm() { - ak_log_test(__func__, ".....=====....."); akfs_map_v3 map; ak_fs_map_v3_init(&map); char *map_string = "28bde5fa7aacd8da0ec84b61cf3a69141686906c00f8cff904c9a0b12f5a4cf061da254feb188c32b711b2e1d6a3853d5ac3fb0bcd3564899bae55dd30470392"; ak_fs_sha512sum_string_to_struct(map_string, &(map.mh)); if ( ak_fs_map_v3_open_from_file(&map) != 0 ) { - ak_log_debug(__func__, "FAILED"); + ak_log_test(__func__, "FAILED"); return; } - ak_fs_cfm(&map); + if ( ak_fs_cfm(&map) == 0 ) + { + ak_log_test(__func__, "PASSED"); + } + else + { + ak_log_test(__func__, "FAILED"); + } } |