It is now impossible to create a view with a name identical to one of an
existing written view
This commit is contained in:
@ -56,6 +56,7 @@ from .capi.obiview cimport Obiview_p, \
|
||||
obi_new_view_nuc_seqs_cloned_from_name, \
|
||||
obi_open_view, \
|
||||
obi_read_views, \
|
||||
obi_unmap_read_views, \
|
||||
obi_view_delete_column, \
|
||||
obi_view_add_column, \
|
||||
obi_view_get_column, \
|
||||
@ -682,7 +683,7 @@ cdef class OBIDMS :
|
||||
return all_views[view_name]
|
||||
|
||||
|
||||
cpdef dict read_views(self) : # TODO function that gets 1 view with name, function that prints the dic and function that prints 1 view. Add column type in col ref
|
||||
cpdef dict read_views(self) : # TODO function that prints the dic nicely and function that prints 1 view. Add column type in col ref
|
||||
|
||||
cdef Obiviews_infos_all_p all_views_p
|
||||
cdef Obiview_infos_p view_p
|
||||
@ -696,6 +697,8 @@ cdef class OBIDMS :
|
||||
|
||||
views = {}
|
||||
all_views_p = obi_read_views(self.pointer)
|
||||
if all_views_p == NULL :
|
||||
raise Exception("No views to read")
|
||||
nb_views = <int> (all_views_p.header).view_count
|
||||
for i in range(nb_views) :
|
||||
view_p = (<Obiview_infos_p> (all_views_p.view_infos)) + i
|
||||
@ -721,6 +724,8 @@ cdef class OBIDMS :
|
||||
views[view_name]["column_references"][column_name] = {}
|
||||
views[view_name]["column_references"][column_name]["version"] = column_refs[j].version
|
||||
|
||||
obi_unmap_read_views(all_views_p);
|
||||
|
||||
return views
|
||||
|
||||
|
||||
|
@ -81,6 +81,8 @@ cdef extern from "obiview.h" nogil:
|
||||
|
||||
Obiviews_infos_all_p obi_read_views(OBIDMS_p dms)
|
||||
|
||||
int obi_unmap_read_views(Obiviews_infos_all_p views)
|
||||
|
||||
int obi_view_add_column(Obiview_p view,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number,
|
||||
|
@ -224,6 +224,8 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
|
||||
}
|
||||
|
||||
view = obi_new_view(dms, view_name, view_to_clone, line_selection, comments);
|
||||
if (view== NULL)
|
||||
return NULL;
|
||||
|
||||
strcpy(view->view_type, VIEW_TYPE_NUC_SEQS);
|
||||
|
||||
@ -258,6 +260,24 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
Obiview_p view;
|
||||
int i;
|
||||
index_t line_nb;
|
||||
Obiviews_infos_all_p views_infos;
|
||||
|
||||
// Check uniqueness of name TODO but problem if view not written yet has the same name
|
||||
views_infos = obi_read_views(dms);
|
||||
if (views_infos != NULL)
|
||||
{
|
||||
for (i=0; i<((views_infos->header)->view_count); i++)
|
||||
{
|
||||
if (strcmp(((views_infos->view_infos)+i)->name, view_name) == 0) // TODO discuss what to do
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nView name already exists for a previous view");
|
||||
obi_unmap_read_views(views_infos);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
obi_unmap_read_views(views_infos);
|
||||
}
|
||||
|
||||
view = (Obiview_p) malloc(sizeof(Obiview_t));
|
||||
if (view == NULL)
|
||||
@ -646,6 +666,28 @@ Obiviews_infos_all_p obi_read_views(OBIDMS_p dms)
|
||||
}
|
||||
|
||||
|
||||
int obi_unmap_read_views(Obiviews_infos_all_p views)
|
||||
{
|
||||
if (munmap(views->view_infos, (views->header)->views_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError unmapping the views of an obiview file");
|
||||
free(views);
|
||||
return -1;
|
||||
}
|
||||
if (munmap(views->header, (views->header)->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError unmapping the header of an obiview file");
|
||||
free(views);
|
||||
return -1;
|
||||
|
||||
}
|
||||
free(views);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_view_add_column(Obiview_p view,
|
||||
const char* column_name,
|
||||
obiversion_t version_number,
|
||||
|
@ -153,6 +153,8 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
|
||||
|
||||
Obiviews_infos_all_p obi_read_views(OBIDMS_p dms);
|
||||
|
||||
int obi_unmap_read_views(Obiviews_infos_all_p views);
|
||||
|
||||
int obi_view_add_column(Obiview_p view,
|
||||
const char* column_name,
|
||||
obiversion_t version_number,
|
||||
|
Reference in New Issue
Block a user