obi import: rewriting a column now deletes the old one to save disk
space
This commit is contained in:
@ -102,7 +102,7 @@ cdef extern from "obiview.h" nogil:
|
|||||||
const_char_p comments,
|
const_char_p comments,
|
||||||
bint create)
|
bint create)
|
||||||
|
|
||||||
int obi_view_delete_column(Obiview_p view, const_char_p column_name)
|
int obi_view_delete_column(Obiview_p view, const_char_p column_name, bint delete_file)
|
||||||
|
|
||||||
OBIDMS_column_p obi_view_get_column(Obiview_p view, const_char_p column_name)
|
OBIDMS_column_p obi_view_get_column(Obiview_p view, const_char_p column_name)
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ cdef class View(OBIWrapper):
|
|||||||
cdef inline Obiview_p pointer(self)
|
cdef inline Obiview_p pointer(self)
|
||||||
|
|
||||||
cpdef delete_column(self,
|
cpdef delete_column(self,
|
||||||
object column_name)
|
object column_name,
|
||||||
|
bint delete_file=*)
|
||||||
|
|
||||||
cpdef rename_column(self,
|
cpdef rename_column(self,
|
||||||
object current_name,
|
object current_name,
|
||||||
|
@ -227,7 +227,8 @@ cdef class View(OBIWrapper) :
|
|||||||
|
|
||||||
|
|
||||||
cpdef delete_column(self,
|
cpdef delete_column(self,
|
||||||
object column_name) :
|
object column_name,
|
||||||
|
bint delete_file=False) :
|
||||||
|
|
||||||
cdef bytes column_name_b = tobytes(column_name)
|
cdef bytes column_name_b = tobytes(column_name)
|
||||||
|
|
||||||
@ -239,7 +240,7 @@ cdef class View(OBIWrapper) :
|
|||||||
col.close()
|
col.close()
|
||||||
|
|
||||||
# Remove the column from the view which closes the C structure
|
# Remove the column from the view which closes the C structure
|
||||||
if obi_view_delete_column(self.pointer(), column_name_b) < 0 :
|
if obi_view_delete_column(self.pointer(), column_name_b, delete_file) < 0 :
|
||||||
raise RollbackException("Problem deleting column %s from a view",
|
raise RollbackException("Problem deleting column %s from a view",
|
||||||
bytes2str(column_name_b), self)
|
bytes2str(column_name_b), self)
|
||||||
|
|
||||||
@ -307,7 +308,7 @@ cdef class View(OBIWrapper) :
|
|||||||
new_column[i] = old_column[i]
|
new_column[i] = old_column[i]
|
||||||
|
|
||||||
# Remove old column from view
|
# Remove old column from view
|
||||||
self.delete_column(column_name_b)
|
self.delete_column(column_name_b, delete_file=True)
|
||||||
|
|
||||||
# Rename new
|
# Rename new
|
||||||
new_column.name = column_name_b
|
new_column.name = column_name_b
|
||||||
|
@ -2380,11 +2380,12 @@ int obi_view_add_column(Obiview_p view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int obi_view_delete_column(Obiview_p view, const char* column_name)
|
int obi_view_delete_column(Obiview_p view, const char* column_name, bool delete_file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bool found;
|
bool found;
|
||||||
OBIDMS_column_p column;
|
OBIDMS_column_p column;
|
||||||
|
char* col_to_delete_path;
|
||||||
|
|
||||||
// Check that the view is not read-only
|
// Check that the view is not read-only
|
||||||
if (view->read_only)
|
if (view->read_only)
|
||||||
@ -2406,8 +2407,31 @@ int obi_view_delete_column(Obiview_p view, const char* column_name)
|
|||||||
obidebug(1, "\nError getting a column from the linked list of column pointers of a view when deleting a column from a view");
|
obidebug(1, "\nError getting a column from the linked list of column pointers of a view when deleting a column from a view");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// Keep column path if need to delete the file
|
||||||
|
if (delete_file)
|
||||||
|
{
|
||||||
|
col_to_delete_path = obi_column_full_path(view->dms, column->header->name, column->header->version);
|
||||||
|
if (col_to_delete_path == NULL)
|
||||||
|
{
|
||||||
|
obidebug(1, "\nError getting a column file path when deleting a column");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
obi_close_column(column);
|
obi_close_column(column);
|
||||||
|
|
||||||
|
// Delete file if needed
|
||||||
|
if (delete_file)
|
||||||
|
{
|
||||||
|
if (remove(col_to_delete_path) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obidebug(1, "\nError deleting a column file when deleting unfinished columns: file %s", col_to_delete_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(col_to_delete_path);
|
||||||
|
}
|
||||||
|
|
||||||
view->columns = ll_delete(view->columns, i);
|
view->columns = ll_delete(view->columns, i);
|
||||||
// TODO how do we check for error? NULL can be empty list
|
// TODO how do we check for error? NULL can be empty list
|
||||||
found = true;
|
found = true;
|
||||||
@ -3047,7 +3071,7 @@ int obi_create_auto_id_column(Obiview_p view, const char* prefix)
|
|||||||
// Delete old ID column if it exists
|
// Delete old ID column if it exists
|
||||||
if (obi_view_get_column(view, ID_COLUMN) != NULL)
|
if (obi_view_get_column(view, ID_COLUMN) != NULL)
|
||||||
{
|
{
|
||||||
if (obi_view_delete_column(view, ID_COLUMN) < 0)
|
if (obi_view_delete_column(view, ID_COLUMN, false) < 0)
|
||||||
{
|
{
|
||||||
obidebug(1, "Error deleting an ID column to replace it in a view");
|
obidebug(1, "Error deleting an ID column to replace it in a view");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -440,6 +440,7 @@ int obi_view_add_column(Obiview_p view,
|
|||||||
*
|
*
|
||||||
* @param view A pointer on the view.
|
* @param view A pointer on the view.
|
||||||
* @param column_name The name of the column that should be deleted from the view.
|
* @param column_name The name of the column that should be deleted from the view.
|
||||||
|
* @param delete_file Whether the column file should be deleted. Use carefully re: dependencies.
|
||||||
*
|
*
|
||||||
* @returns A value indicating the success of the operation.
|
* @returns A value indicating the success of the operation.
|
||||||
* @retval 0 if the operation was successfully completed.
|
* @retval 0 if the operation was successfully completed.
|
||||||
@ -448,7 +449,7 @@ int obi_view_add_column(Obiview_p view,
|
|||||||
* @since February 2016
|
* @since February 2016
|
||||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
int obi_view_delete_column(Obiview_p view, const char* column_name);
|
int obi_view_delete_column(Obiview_p view, const char* column_name, bool delete_file);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user