Commit 527d3555 by Celine Mercier

Moved the functions getting full paths for files and directories to

obidms.c/.h files
parent 71492ad2
......@@ -510,7 +510,7 @@ char* get_full_path_of_avl_dir(OBIDMS_p dms, const char* avl_name)
{
char* avl_dir_name;
avl_dir_name = get_full_path(dms, INDEXER_DIR_NAME);
avl_dir_name = obi_dms_get_full_path(dms, INDEXER_DIR_NAME);
if (avl_dir_name == NULL)
{
obidebug(1, "\nError getting path for the DMS AVL directory");
......@@ -1286,33 +1286,16 @@ int obi_avl_exists(OBIDMS_p dms, const char* avl_name)
{
struct stat buffer;
char* avl_dir_path;
char* avl_dir_relative_path;
int relative_path_size;
int check_dir;
// Build the AVL tree file path
relative_path_size = strlen(avl_name) + strlen(INDEXER_DIR_NAME) + 2;
avl_dir_relative_path = (char*) malloc(relative_path_size*sizeof(char));
if (avl_dir_relative_path == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for the path to the AVL directory");
return -1;
}
strcpy(avl_dir_relative_path, INDEXER_DIR_NAME);
strcat(avl_dir_relative_path, "/");
strcat(avl_dir_relative_path, avl_name);
avl_dir_path = get_full_path(dms, avl_dir_relative_path);
avl_dir_path = get_full_path_of_avl_dir(dms, avl_name);
if (avl_dir_path == NULL)
{
obidebug(1, "\nError getting the directory path for an AVL tree");
return -1;
}
check_dir = stat(avl_dir_path, &buffer);
free(avl_dir_path);
free(avl_dir_relative_path);
if (check_dir == 0)
return 1;
......
......@@ -590,7 +590,7 @@ int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer)
}
char* get_full_path(OBIDMS_p dms, const char* path_name)
char* obi_dms_get_dms_path(OBIDMS_p dms)
{
char* full_path;
......@@ -602,8 +602,8 @@ char* get_full_path(OBIDMS_p dms, const char* path_name)
return NULL;
}
if (getcwd(full_path, MAX_PATH_LEN) == NULL)
{
if (getcwd(full_path, MAX_PATH_LEN) == NULL) // TODO not sure at all about this because the DMS must be in the working directory.
{ // Maybe better to store when opening, but opening function seems to assume that too.
obi_set_errno(OBI_UTILS_ERROR);
obidebug(1, "\nError getting the path to a file or directory");
return NULL;
......@@ -611,6 +611,16 @@ char* get_full_path(OBIDMS_p dms, const char* path_name)
strcat(full_path, "/");
strcat(full_path, dms->directory_name);
return full_path;
}
char* obi_dms_get_full_path(OBIDMS_p dms, const char* path_name)
{
char* full_path;
full_path = obi_dms_get_dms_path(dms);
strcat(full_path, "/");
strcat(full_path, path_name);
......@@ -623,7 +633,7 @@ DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name)
char* full_path;
DIR* directory;
full_path = get_full_path(dms, path_name);
full_path = obi_dms_get_full_path(dms, path_name);
if (full_path == NULL)
return NULL;
......
......@@ -208,6 +208,9 @@ void obi_dms_list_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
char* obi_dms_get_path(OBIDMS_p dms);
/** TODO
* @brief Internal function getting the full path of a file or a directory from its
* path relative to a directory file descriptor.
......@@ -224,7 +227,7 @@ int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
char* get_full_path(OBIDMS_p dms, const char* path_name);
char* obi_dms_get_full_path(OBIDMS_p dms, const char* path_name);
/**
......
......@@ -379,7 +379,7 @@ OBIDMS_taxonomy_p obi_read_taxonomy(OBIDMS_p dms, const char* taxonomy_name, boo
buffer_size = 2048; // TODO
main_taxonomy_dir_path = get_full_path(dms, TAXONOMY_DIR_NAME);
main_taxonomy_dir_path = obi_dms_get_full_path(dms, TAXONOMY_DIR_NAME);
taxonomy_path = (char*) malloc((strlen(main_taxonomy_dir_path) + strlen(taxonomy_name) + strlen(taxonomy_name) + 3)*sizeof(char));
if (sprintf(taxonomy_path, "%s/%s/%s", main_taxonomy_dir_path, taxonomy_name, taxonomy_name) < 0)
{
......
......@@ -105,7 +105,7 @@ int obi_column_directory_exists(OBIDMS_p dms, const char* column_name)
return -1;
// Get the full path for the column directory
full_path = get_full_path(dms, column_directory_name);
full_path = obi_dms_get_full_path(dms, column_directory_name);
if (full_path == NULL)
{
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
......
......@@ -1051,7 +1051,7 @@ int obi_save_view(Obiview_p view)
return -1;
// Get the full path for the column directory
full_path = get_full_path(view->dms, view_file_name);
full_path = obi_dms_get_full_path(view->dms, view_file_name);
if (full_path == NULL)
{
obi_set_errno(OBIVIEW_ERROR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment