Commit 4cb52e16 authored by Celine Mercier's avatar Celine Mercier

Made the truncating of columns automatic when closing them (note:

already the case for AVLs)
parent 9d042f7b
......@@ -5,7 +5,7 @@ from obitools3.utils cimport bytes2str, str2bytes
from .capi.obidms cimport obi_dms, \
obi_close_dms
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
from .capi.obidmscolumn cimport obi_close_column, \
obi_column_format_date, \
OBIDMS_column_p, \
OBIDMS_column_header_p
......@@ -144,7 +144,7 @@ cdef class OBIDMS_column :
return to_print
cpdef close(self):
if obi_truncate_and_close_column((self.pointer)[0]) < 0 :
if obi_close_column((self.pointer)[0]) < 0 :
raise Exception("Problem closing a column")
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obibool_with_elt_name_in_view, \
obi_column_get_obibool_with_elt_idx_in_view, \
obi_column_set_obibool_with_elt_name_in_view, \
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obichar_with_elt_name_in_view, \
obi_column_get_obichar_with_elt_idx_in_view, \
obi_column_set_obichar_with_elt_name_in_view, \
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obifloat_with_elt_name_in_view, \
obi_column_get_obifloat_with_elt_idx_in_view, \
obi_column_set_obifloat_with_elt_name_in_view, \
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obiint_with_elt_name_in_view, \
obi_column_get_obiint_with_elt_idx_in_view, \
obi_column_set_obiint_with_elt_name_in_view, \
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obiseq_with_elt_name_in_view, \
obi_column_get_obiseq_with_elt_idx_in_view, \
obi_column_set_obiseq_with_elt_name_in_view, \
......
#cython: language_level=3
from .capi.obidmscolumn cimport obi_truncate_and_close_column
from .capi.obiview cimport obi_column_get_obistr_with_elt_name_in_view, \
obi_column_get_obistr_with_elt_idx_in_view, \
obi_column_set_obistr_with_elt_name_in_view, \
......
......@@ -60,7 +60,7 @@ cdef extern from "obidmscolumn.h" nogil:
obiversion_t version_number,
bint clone_data)
int obi_truncate_and_close_column(OBIDMS_column_p column)
int obi_close_column(OBIDMS_column_p column)
obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms,
const_char_p column_name)
......
......@@ -989,6 +989,13 @@ int obi_close_column(OBIDMS_column_p column)
bool close_dir;
Opened_columns_list_p columns_list;
// Truncate the column to the number of lines used if it's not read-only
if (column->writable)
{
if (obi_truncate_column(column) < 0)
return -1;
}
columns_list = (column->dms)->opened_columns;
(column->counter)--;
......@@ -1049,7 +1056,7 @@ int obi_close_column(OBIDMS_column_p column)
}
int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
int obi_truncate_column(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
{
size_t file_size;
size_t data_size;
......@@ -1224,20 +1231,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
}
int obi_truncate_and_close_column(OBIDMS_column_p column)
{
if (column->writable) // TODO discuss
{
if (obi_truncate_column_to_lines_used(column) < 0)
return -1;
}
if (obi_close_column(column) < 0)
return -1;
return 0;
}
void obi_ini_to_NA_values(OBIDMS_column_p column,
index_t first_line_nb,
index_t nb_lines)
......
......@@ -226,7 +226,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, OBIDMS_column_p line_selection, c
/**
* @brief Closes a column.
* @brief Truncates a column to the number of lines used if it is not read-only and closes it.
*
* @param column A pointer on an OBIDMS column.
*
......@@ -251,7 +251,7 @@ int obi_close_column(OBIDMS_column_p column);
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
int obi_truncate_column(OBIDMS_column_p column);
/**
......@@ -268,21 +268,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
int obi_enlarge_column(OBIDMS_column_p column);
/**
* @brief Truncates a column file to the number of lines used rounded to the nearest
* greater multiple of the page size and closes it.
*
* @param column A pointer on an OBIDMS column.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since August 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_truncate_and_close_column(OBIDMS_column_p column);
/*
* @brief Sets the data in a column to the NA value of the data OBIType.
*
......
......@@ -843,18 +843,18 @@ OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
if (!(strcmp((((view->columns)[i])->header)->name, column_name)))
column = (view->columns)[i];
else
obi_truncate_and_close_column(column_buffer); // TODO weird closing after cloning but can't think of cleaner yet
obi_close_column(column_buffer); // TODO weird closing after cloning but can't think of cleaner yet
}
}
if (view->line_selection != NULL)
{
obi_truncate_and_close_column(view->line_selection);
obi_close_column(view->line_selection);
view->line_selection = NULL;
}
if (view->new_line_selection != NULL)
{
obi_truncate_and_close_column(view->new_line_selection);
obi_close_column(view->new_line_selection);
view->new_line_selection = NULL;
}
......@@ -883,7 +883,7 @@ int obi_view_delete_column(Obiview_p view, const char* column_name)
{
if (!strcmp((((view->columns)[i])->header)->name, column_name))
{
obi_truncate_and_close_column((view->columns)[i]);
obi_close_column((view->columns)[i]);
found = 1;
}
if (found)
......
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