Finished fixing issues with DMS paths
This commit is contained in:
38
src/obidms.c
38
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);
|
||||
|
Reference in New Issue
Block a user