From f46ea0b9884d685ef2918e2d8ac544e022abf9cb Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Tue, 30 Aug 2016 11:09:45 +0200 Subject: [PATCH] Finished fixing issues with DMS paths --- src/obidms.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/obidms.c b/src/obidms.c index 750e203..d0eccdc 100644 --- a/src/obidms.c +++ b/src/obidms.c @@ -237,8 +237,6 @@ OBIDMS_p obi_create_dms(const char* dms_path) if (directory_name == NULL) return NULL; - fprintf(stderr, "\ndirectory created = %s\n", directory_name); - // Try to create the directory if (mkdir(directory_name, 00777) < 0) { @@ -310,12 +308,12 @@ OBIDMS_p obi_create_dms(const char* dms_path) OBIDMS_p obi_open_dms(const char* dms_path) { OBIDMS_p dms; - char* directory_name; + char* complete_dms_path; char* infos_file_name; int infos_file_descriptor; bool little_endian_dms; bool little_endian_platform; - size_t i, j, k; + size_t i, j; dms = NULL; @@ -338,36 +336,24 @@ OBIDMS_p obi_open_dms(const char* dms_path) } strcpy(dms->dms_name, dms_path+j); - // Build and check the directory name - directory_name = build_directory_name(dms->dms_name); - if (directory_name == NULL) + // Build and check the directory name including the relative path + complete_dms_path = build_directory_name(dms_path); + if (complete_dms_path == NULL) { free(dms); return NULL; } - // Build and store the absolute path to the DMS directory // TODO rework this, make function? potential problem with relative paths - if (dms_path[0] == '/') // The path is already absolute + // Get and store the absolute path to the DMS directory + if (realpath(complete_dms_path, dms->directory_path) == NULL) { - strncpy(dms->directory_path, dms_path, j); - strcpy((dms->directory_path)+j, directory_name); - } - else // The path is relative - { - if (getcwd(dms->directory_path, MAX_PATH_LEN) == NULL) - { - obi_set_errno(OBIDMS_UNKNOWN_ERROR); - obidebug(1, "\nError getting the absolute path to the current working directory"); - free(directory_name); - return NULL; - } - strcat(dms->directory_path, "/"); - k = strlen(dms->directory_path); - strncat(dms->directory_path, dms_path, j); - strcpy((dms->directory_path)+k+j, directory_name); + obi_set_errno(OBIDMS_UNKNOWN_ERROR); + obidebug(1, "\nError getting the absolute path to the DMS directory"); + free(complete_dms_path); + return NULL; } - free(directory_name); + free(complete_dms_path); // Try to open the directory dms->directory = opendir(dms->directory_path);