Commit 8f724f4f by Celine Mercier

Some code refactoring

parent 35957881
......@@ -660,7 +660,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
return NULL;
}
}
else if ((nb_elements_per_line == 1) && (strcmp(elements_names, column_name) != 0))
else if ((nb_elements_per_line == 1) && (strcmp(elements_names, column_name) != 0)) // TODO Discuss, maybe just make it the column name
{
obidebug(1, "\nCan't create column because the element name does not match the column name");
return NULL;
......@@ -1126,6 +1126,29 @@ int obi_close_column(OBIDMS_column_p column)
}
int obi_clone_column_indexer(OBIDMS_column_p column)
{
char* new_indexer_name;
new_indexer_name = obi_build_indexer_name((column->header)->name, (column->header)->version);
if (new_indexer_name == NULL)
return -1;
column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow?
if (column->indexer == NULL)
{
obidebug(1, "\nError cloning a column's indexer to make it writable");
return -1;
}
strcpy((column->header)->indexer_name, new_indexer_name);
free(new_indexer_name);
return 0;
}
int obi_truncate_column(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
{
size_t file_size;
......
......@@ -238,6 +238,20 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, OBIDMS_column_p line_selection, c
/**
* @brief Clones a column indexer to have it writable.
*
* @param column A pointer on an OBIDMS column.
*
* @retval 0 if the operation was successfully completed.
* @retval -1 if an error occurred.
*
* @since November 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_clone_column_indexer(OBIDMS_column_p 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.
......
......@@ -27,7 +27,6 @@
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value)
{
index_t idx;
char* new_indexer_name;
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
return -1;
......@@ -44,14 +43,9 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
{
if (obi_errno == OBI_READ_ONLY_INDEXER_ERROR)
{
// TODO PUT IN A COLUMN FUNCTION
// If the error is that the indexer is read-only, clone it
new_indexer_name = obi_build_indexer_name((column->header)->name, (column->header)->version);
if (new_indexer_name == NULL)
if (obi_clone_column_indexer(column) < 0)
return -1;
column->indexer = obi_clone_indexer(column->indexer, new_indexer_name); // TODO Need to lock this somehow?
strcpy((column->header)->indexer_name, new_indexer_name);
free(new_indexer_name);
obi_set_errno(0);
// Add the value in the new indexer
......
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