DMS are now locked when used by a command. Added checks and changed

cleaning mechanisms.
This commit is contained in:
Celine Mercier
2019-09-20 20:37:19 +02:00
parent eb6c59dc1e
commit 783a1343c4
14 changed files with 378 additions and 28 deletions

View File

@ -2594,6 +2594,74 @@ int obi_save_and_close_view(Obiview_p view)
}
int obi_dms_has_unfinished_views(OBIDMS_p dms)
{
struct dirent* dp;
int i;
char* full_path;
char* relative_path;
Obiview_infos_p view_infos;
char* view_name;
int ret_value;
char* to_delete[1000];
int d;
ret_value = 0;
d = 0;
// Look for unfinished views and delete them
rewinddir(dms->view_directory);
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
i=0;
while ((dp->d_name)[i] != '.')
i++;
relative_path = (char*) malloc(strlen(VIEW_DIR_NAME) + strlen(dp->d_name) + 2);
strcpy(relative_path, VIEW_DIR_NAME);
strcat(relative_path, "/");
strcat(relative_path, dp->d_name);
full_path = obi_dms_get_full_path(dms, relative_path);
free(relative_path);
if (full_path == NULL)
{
obidebug(1, "\nError getting the full path to a view file when cleaning unfinished views");
ret_value = -1;
continue;
}
if (strcmp((dp->d_name)+i, ".obiview_unfinished") == 0)
ret_value = 1;
else if (strcmp((dp->d_name)+i, ".obiview") == 0)
{ // Check if the view was properly flagged as finished
view_name = (char*) malloc((i+1) * sizeof(char));
if (view_name == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for a view name when deleting unfinished views: file %s", dp->d_name);
ret_value = -1;
continue;
}
strncpy(view_name, dp->d_name, i);
view_name[i] = '\0';
view_infos = obi_view_map_file(dms, view_name, true);
if (view_infos == NULL)
{
obidebug(1, "\nError reading a view file when deleting unfinished views: file %s", dp->d_name);
ret_value = -1;
continue;
}
if (view_infos->finished == false)
ret_value = 1;
}
}
return ret_value;
}
int obi_clean_unfinished_views(OBIDMS_p dms)
{
struct dirent* dp;