Fixed bug where column directories weren't closed correctly, leading to
too many file descriptors open, and added error checking when closing file descriptors
This commit is contained in:
@ -317,7 +317,12 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(version_file_descriptor);
|
||||
if (close(version_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a version file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return new_version_number;
|
||||
}
|
||||
@ -403,7 +408,12 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(version_file_descriptor);
|
||||
if (close(version_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a version file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return version_number;
|
||||
}
|
||||
@ -480,7 +490,12 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(version_file_descriptor);
|
||||
if (close(version_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a version file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return latest_version_number;
|
||||
}
|
||||
@ -794,7 +809,12 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
// Fill the data with NA values
|
||||
obi_ini_to_NA_values(new_column, 0, nb_lines);
|
||||
|
||||
close(column_file_descriptor);
|
||||
if (close(column_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a column file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Add in the list of opened columns
|
||||
obi_dms_list_column(dms, new_column);
|
||||
@ -940,7 +960,12 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
}
|
||||
}
|
||||
|
||||
close(column_file_descriptor);
|
||||
if (close(column_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a column file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Add in the list of opened columns
|
||||
obi_dms_list_column(dms, column);
|
||||
@ -999,10 +1024,11 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError creating the new column when cloning a column");
|
||||
// The new file is deleted
|
||||
const char* column_file_name = build_column_file_name(column_name, version_number);
|
||||
if (remove(column_file_name) < 0)
|
||||
obidebug(1, "\nError deleting a bad cloned file");
|
||||
// The new file is deleted TODO check if it exists before
|
||||
//const char* column_file_name = build_column_file_name(column_name, version_number);
|
||||
//if (remove(column_file_name) < 0)
|
||||
// obidebug(1, "\nError deleting a bad cloned file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(new_column->header)->cloned_from = (column_to_clone->header)->version;
|
||||
@ -1036,7 +1062,6 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
bool close_dir;
|
||||
int ret_val = 0;
|
||||
|
||||
// Truncate the column to the number of lines used if it's not read-only
|
||||
@ -1051,9 +1076,6 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
if (obi_dms_unlist_column(column->dms, column) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
// Close column directory if it was the last column opened from that directory
|
||||
close_dir = obi_dms_is_column_name_in_list(column->dms, (column->header)->name);
|
||||
|
||||
// If the data type is OBI_STR, OBI_SEQ or OBI_QUAL, the associated indexer is closed
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ) || ((column->header)->returned_data_type == OBI_QUAL))
|
||||
if (obi_close_indexer(column->indexer) < 0)
|
||||
@ -1076,9 +1098,8 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
}
|
||||
|
||||
// Close column directory
|
||||
if (close_dir)
|
||||
if (obi_close_column_directory(column->column_directory) < 0)
|
||||
ret_val = -1;
|
||||
if (obi_close_column_directory(column->column_directory) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
free(column);
|
||||
}
|
||||
@ -1164,7 +1185,12 @@ int obi_truncate_column(OBIDMS_column_p column) // TODO is it necessary to unmap
|
||||
(column->header)->line_count = new_line_count;
|
||||
(column->header)->data_size = data_size;
|
||||
|
||||
close(column_file_descriptor);
|
||||
if (close(column_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a column file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1264,7 +1290,12 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
// Initialize new data lines to NA
|
||||
obi_ini_to_NA_values(column, old_line_count, new_line_count - old_line_count);
|
||||
|
||||
close(column_file_descriptor);
|
||||
if (close(column_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a column file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1407,7 +1438,12 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
return NULL;
|
||||
}
|
||||
|
||||
close(column_file_descriptor);
|
||||
if (close(column_file_descriptor) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError closing a column file");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
Reference in New Issue
Block a user