Closes issue #47 by storing each view in a separate file named with the
view's name and created upon view creation.
This commit is contained in:
43
src/obidms.c
43
src/obidms.c
@ -252,7 +252,7 @@ OBIDMS_p obi_create_dms(const char* dms_path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get file descriptor of DMS directory to create the indexer directory
|
||||
// Get file descriptor of DMS directory to create other directories
|
||||
dms_dir = opendir(directory_name);
|
||||
if (dms_dir == NULL)
|
||||
{
|
||||
@ -280,6 +280,14 @@ OBIDMS_p obi_create_dms(const char* dms_path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create the view directory
|
||||
if (mkdirat(dms_file_descriptor, VIEW_DIR_NAME, 00777) < 0)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nProblem creating a view directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Isolate the dms name
|
||||
j = 0;
|
||||
for (i=0; i<strlen(dms_path); i++)
|
||||
@ -447,6 +455,30 @@ OBIDMS_p obi_open_dms(const char* dms_path)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open the view directory
|
||||
dms->view_directory = opendir_in_dms(dms, VIEW_DIR_NAME);
|
||||
if (dms->view_directory == NULL)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening the view directory");
|
||||
closedir(dms->indexer_directory);
|
||||
closedir(dms->directory);
|
||||
free(dms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Store the view directory's file descriptor
|
||||
dms->view_dir_fd = dirfd(dms->view_directory);
|
||||
if (dms->view_dir_fd < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError getting the file descriptor of the view directory");
|
||||
closedir(dms->view_directory);
|
||||
closedir(dms->directory);
|
||||
free(dms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initialize the list of opened columns
|
||||
dms->opened_columns = (Opened_columns_list_p) malloc(sizeof(Opened_columns_list_t));
|
||||
(dms->opened_columns)->nb_opened_columns = 0;
|
||||
@ -486,7 +518,7 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
while ((dms->opened_columns)->nb_opened_columns > 0)
|
||||
obi_close_column(*((dms->opened_columns)->columns));
|
||||
|
||||
// Close dms and indexer directories
|
||||
// Close dms, and view and indexer directories
|
||||
if (closedir(dms->directory) < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
||||
@ -501,6 +533,13 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
if (closedir(dms->view_directory) < 0)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError closing a view directory");
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
free(dms);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
*/
|
||||
#define INDEXER_DIR_NAME "OBIBLOB_INDEXERS" /**< The name of the Obiblob indexer directory.
|
||||
*/
|
||||
#define VIEW_DIR_NAME "VIEWS" /**< The name of the view directory.
|
||||
*/
|
||||
#define TAXONOMY_DIR_NAME "TAXONOMY" /**< The name of the taxonomy directory.
|
||||
*/
|
||||
#define MAX_NB_OPENED_COLUMNS (100) /**< The maximum number of columns open at the same time.
|
||||
@ -98,6 +100,12 @@ typedef struct OBIDMS {
|
||||
int indexer_dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the indexer directory.
|
||||
*/
|
||||
DIR* view_directory; /**< A directory entry usable to
|
||||
* refer and scan the view directory.
|
||||
*/
|
||||
int view_dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the view directory.
|
||||
*/
|
||||
bool little_endian; /**< Endianness of the database.
|
||||
*/
|
||||
Opened_columns_list_p opened_columns; /**< List of opened columns.
|
||||
|
843
src/obiview.c
843
src/obiview.c
File diff suppressed because it is too large
Load Diff
@ -34,8 +34,6 @@
|
||||
*/
|
||||
#define VIEW_TYPE_MAX_LENGTH (1024) /**< The maximum length of the type name of a view.
|
||||
*/
|
||||
#define OBIVIEW_FILE_NAME "obiviews" /**< The default name of a view file.
|
||||
*/
|
||||
#define LINES_COLUMN_NAME "LINES" /**< The name of the column containing the line selections
|
||||
* in all views.
|
||||
*/
|
||||
@ -56,45 +54,6 @@
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure for an opened view.
|
||||
*/
|
||||
typedef struct Obiview {
|
||||
|
||||
OBIDMS_p dms; /**< A pointer on the DMS to which the view belongs.
|
||||
*/
|
||||
char name[OBIVIEW_NAME_MAX_LENGTH+1]; /**< Name of the view.
|
||||
*/
|
||||
char created_from[OBIVIEW_NAME_MAX_LENGTH+1]; /**< Name of the view from which that view was cloned if the view was cloned.
|
||||
*/
|
||||
char view_type[VIEW_TYPE_MAX_LENGTH+1]; /**< Type of the view if there is one.
|
||||
* Types existing: NUC_SEQS_VIEW.
|
||||
*/
|
||||
bool read_only; /**< Whether the view is read-only or can be modified.
|
||||
*/
|
||||
OBIDMS_column_p line_selection; /**< A pointer on the column containing the line selection
|
||||
* associated with the view if there is one.
|
||||
* This line selection is read-only, and when a line from the view is read,
|
||||
* it is this line selection that is used.
|
||||
*/
|
||||
OBIDMS_column_p new_line_selection; /**< A pointer on the column containing the new line selection being built
|
||||
* to associate with the view, if there is one.
|
||||
* When a line is selected with obi_select_line() or obi_select_lines(),
|
||||
* it is recorded in this line selection.
|
||||
*/
|
||||
index_t line_count; /**< The number of lines in the view. Refers to the number of lines in each
|
||||
* column of the view if line_selection is NULL, or to the line count of
|
||||
* line_selection if it is not NULL.
|
||||
*/
|
||||
int column_count; /**< The number of columns in the view.
|
||||
*/
|
||||
OBIDMS_column_p columns[MAX_NB_OPENED_COLUMNS]; /**< Array of pointers on all the columns of the view.
|
||||
*/
|
||||
char comments[OBIVIEW_COMMENTS_MAX_LENGTH+1]; /**< Comments, additional informations on the view.
|
||||
*/
|
||||
} Obiview_t, *Obiview_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure referencing a column by its name and its version.
|
||||
*/
|
||||
@ -112,8 +71,6 @@ typedef struct Column_reference {
|
||||
* Once a view has been written in the view file, it can not be modified and can only be read.
|
||||
*/
|
||||
typedef struct Obiview_infos {
|
||||
int view_number; /**< Number of the view in the view file.
|
||||
*/
|
||||
time_t creation_date; /**< Time at which the view was written in the view file.
|
||||
*/
|
||||
char name[OBIVIEW_NAME_MAX_LENGTH+1]; /**< Name of the view, used to identify it.
|
||||
@ -138,7 +95,29 @@ typedef struct Obiview_infos {
|
||||
} Obiview_infos_t, *Obiview_infos_p;
|
||||
|
||||
|
||||
// TODO : Combine the common elements of the Obiview_infos and Obiview structures in one structure used by both?
|
||||
/**
|
||||
* @brief Structure for an opened view.
|
||||
*/
|
||||
typedef struct Obiview {
|
||||
Obiview_infos_p infos; /**< A pointer on the mapped view informations.
|
||||
*/
|
||||
OBIDMS_p dms; /**< A pointer on the DMS to which the view belongs.
|
||||
*/
|
||||
bool read_only; /**< Whether the view is read-only or can be modified.
|
||||
*/
|
||||
OBIDMS_column_p line_selection; /**< A pointer on the column containing the line selection
|
||||
* associated with the view if there is one.
|
||||
* This line selection is read-only, and when a line from the view is read,
|
||||
* it is this line selection that is used.
|
||||
*/
|
||||
OBIDMS_column_p new_line_selection; /**< A pointer on the column containing the new line selection being built
|
||||
* to associate with the view, if there is one.
|
||||
* When a line is selected with obi_select_line() or obi_select_lines(),
|
||||
* it is recorded in this line selection.
|
||||
*/
|
||||
OBIDMS_column_p columns[MAX_NB_OPENED_COLUMNS]; /**< Array of pointers on all the columns of the view.
|
||||
*/
|
||||
} Obiview_t, *Obiview_p;
|
||||
|
||||
|
||||
/**
|
||||
@ -269,6 +248,37 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
|
||||
Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_name, const char* view_to_clone_name, index_t* line_selection, const char* comments);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Maps a view file and returns the mapped structure stored in it.
|
||||
*
|
||||
* @param dms A pointer on the OBIDMS.
|
||||
* @param view_name The unique name identifying the view.
|
||||
*
|
||||
* @returns A pointer on the mapped view infos structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Unmaps a view file.
|
||||
*
|
||||
* @param dms A pointer on the OBIDMS.
|
||||
* @param view_infos A pointer on the mapped view infos structure.
|
||||
*
|
||||
* @returns A value indicating the success of the operation.
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since June 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens a view identified by its name stored in the view file.
|
||||
*
|
||||
|
Reference in New Issue
Block a user