Commit 5b2e370f by Celine Mercier

Fixed a bug when using an absolute path for a DMS

parent 8d360b0f
......@@ -237,6 +237,8 @@ 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)
{
......@@ -308,12 +310,12 @@ OBIDMS_p obi_create_dms(const char* dms_path)
OBIDMS_p obi_open_dms(const char* dms_path)
{
OBIDMS_p dms;
char* relative_directory_path;
char* directory_name;
char* infos_file_name;
int infos_file_descriptor;
bool little_endian_dms;
bool little_endian_platform;
size_t i, j;
size_t i, j, k;
dms = NULL;
......@@ -326,35 +328,46 @@ OBIDMS_p obi_open_dms(const char* dms_path)
return NULL;
}
// Isolate and store the dms name
j = 0;
for (i=0; i<strlen(dms_path); i++)
{
if (dms_path[i] == '/')
j = i+1;
i++;
}
strcpy(dms->dms_name, dms_path+j);
// Build and check the directory name
relative_directory_path = build_directory_name(dms_path);
if (relative_directory_path == NULL)
directory_name = build_directory_name(dms->dms_name);
if (directory_name == NULL)
{
free(dms);
return NULL;
}
// Build and store the absolute path to the DMS
if (getcwd(dms->directory_path, MAX_PATH_LEN) == 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
{
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
obidebug(1, "\nError getting the absolute path to the current working directory");
free(relative_directory_path);
return NULL;
strncpy(dms->directory_path, dms_path, j);
strcpy((dms->directory_path)+j, directory_name);
}
strcat(dms->directory_path, "/");
strcat(dms->directory_path, relative_directory_path);
free(relative_directory_path);
// Isolate and store the dms name
j = 0;
for (i=0; i<strlen(dms_path); i++)
else // The path is relative
{
if (dms_path[i] == '/')
j = i+1;
i++;
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);
}
strcpy(dms->dms_name, dms_path+j);
free(directory_name);
// Try to open the directory
dms->directory = opendir(dms->directory_path);
......
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