Fixed a bug when using an absolute path for a DMS
This commit is contained in:
57
src/obidms.c
57
src/obidms.c
@ -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,26 +328,6 @@ OBIDMS_p obi_open_dms(const char* dms_path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Build and check the directory name
|
||||
relative_directory_path = build_directory_name(dms_path);
|
||||
if (relative_directory_path == NULL)
|
||||
{
|
||||
free(dms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Build and store the absolute path to the DMS
|
||||
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(relative_directory_path);
|
||||
return NULL;
|
||||
}
|
||||
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++)
|
||||
@ -356,6 +338,37 @@ 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
free(directory_name);
|
||||
|
||||
// Try to open the directory
|
||||
dms->directory = opendir(dms->directory_path);
|
||||
if (dms->directory == NULL)
|
||||
|
Reference in New Issue
Block a user