From 07551151da53dcdcb69bad18afac17b78e6f2e9c Mon Sep 17 00:00:00 2001 From: John Jones Date: Wed, 20 Sep 2017 10:50:32 -0500 Subject: [PATCH] Fixing of test_core_api_object_cat --- core/client_api.c | 6 ++++-- repo/init.c | 11 ++++++++--- test/core/test_api.h | 10 +++++++--- test/testit.c | 2 ++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/client_api.c b/core/client_api.c index eef4c49..a80f4e0 100644 --- a/core/client_api.c +++ b/core/client_api.c @@ -42,12 +42,14 @@ int api_running(struct IpfsNode* local_node) { return 0; } - bzero((char *) &serv_addr, sizeof(serv_addr)); + memset(&serv_addr, 0, sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; + memmove(&serv_addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length); + /* bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); - + */ serv_addr.sin_port = htons(portno); int retVal = connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)); close(sockfd); diff --git a/repo/init.c b/repo/init.c index 458162b..4f9160e 100644 --- a/repo/init.c +++ b/repo/init.c @@ -50,9 +50,14 @@ char* ipfs_repo_get_home_directory(int argc, char** argv) { */ int ipfs_repo_get_directory(int argc, char** argv, char** repo_dir) { char* home = ipfs_repo_get_home_directory(argc, argv); - int dir_len = strlen(home) + 7; - *repo_dir = malloc(dir_len); - os_utils_filepath_join(home, ".ipfs", *repo_dir, dir_len); + // it shouldn't include the .ipfs directory, but if it does, we're done + if (strstr(home, ".ipfs") == NULL) { + int dir_len = strlen(home) + 7; + *repo_dir = malloc(dir_len); + os_utils_filepath_join(home, ".ipfs", *repo_dir, dir_len); + } else { + *repo_dir = home; + } return os_utils_directory_exists(*repo_dir); } diff --git a/test/core/test_api.h b/test/core/test_api.h index fe5b45e..30a4824 100644 --- a/test/core/test_api.h +++ b/test/core/test_api.h @@ -1,7 +1,11 @@ +#include + #include "../test_helper.h" #include "libp2p/utils/logger.h" #include "ipfs/core/client_api.h" #include "ipfs/core/daemon.h" +#include "ipfs/importer/exporter.h" +#include "ipfs/importer/importer.h" int test_core_api_startup_shutdown() { char* repo_path = "/tmp/ipfs_1"; @@ -42,9 +46,9 @@ int test_core_api_object_cat() { pthread_t daemon_thread2; int thread_started1 = 0; int thread_started2 = 0; - char* ipfs_path1 = "/tmp/ipfs_1"; + char* ipfs_path1 = "/tmp/ipfs_1/.ipfs"; char* config_file1 = "config.test1"; - char* ipfs_path2 = "/tmp/ipfs_2"; + char* ipfs_path2 = "/tmp/ipfs_2/.ipfs"; char* config_file2 = "config.test2"; struct FSRepo* fs_repo = NULL; char hash[256] = ""; @@ -96,7 +100,7 @@ int test_core_api_object_cat() { ipfs_node_offline_new(ipfs_path1, &local_node); ipfs_import_file(NULL, filename, &node, local_node, &bytes_written, 0); memset(hash, 0, 256); - ipfs_cid_hash_to_base58(node->hash, node->hash_size, hash, 256); + ipfs_cid_hash_to_base58(node->hash, node->hash_size, (unsigned char*)hash, 256); ipfs_node_free(local_node); ipfs_hashtable_node_free(node); diff --git a/test/testit.c b/test/testit.c index e06eb00..429b396 100644 --- a/test/testit.c +++ b/test/testit.c @@ -48,6 +48,7 @@ const char* names[] = { "test_cid_cast_non_multihash", "test_cid_protobuf_encode_decode", "test_core_api_startup_shutdown", + "test_core_api_object_cat", "test_daemon_startup_shutdown", "test_datastore_list_journal", "test_journal_db", @@ -111,6 +112,7 @@ int (*funcs[])(void) = { test_cid_cast_non_multihash, test_cid_protobuf_encode_decode, test_core_api_startup_shutdown, + test_core_api_object_cat, test_daemon_startup_shutdown, test_datastore_list_journal, test_journal_db,