Commit 00014eb0 by Celine Mercier

View files now have the *.obiview extension

parent acc0da2d
......@@ -100,7 +100,7 @@ int write_comments_to_view_file(Obiview_p view, const char* comments);
* @since June 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static char* build_obiview_file_name(const char* view_name); // TODO delete after discussion
static char* build_obiview_file_name(const char* view_name);
/**
......@@ -402,28 +402,28 @@ char* view_check_all_predicates(Obiview_p view);
*
************************************************************************/
// TODO
//static char* build_obiview_file_name(const char* view_name)
//{
// char* file_name;
//
// // Build file name
// file_name = (char*) malloc((strlen(view_name) + 1)*sizeof(char));
// if (file_name == NULL)
// {
// obi_set_errno(OBI_MALLOC_ERROR);
// obidebug(1, "\nError allocating memory for a view file name");
// return NULL;
// }
// if (sprintf(file_name, view_name) < 0)
// {
// obi_set_errno(OBIVIEW_ERROR);
// obidebug(1, "\nProblem building an obiview file name");
// return NULL;
// }
//
// return file_name;
//}
static char* build_obiview_file_name(const char* view_name)
{
char* file_name;
// Build file name
file_name = (char*) malloc((strlen(view_name) + 8 + 1)*sizeof(char));
if (file_name == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for a view file name");
return NULL;
}
if (sprintf(file_name, "%s.obiview", view_name) < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nProblem building an obiview file name");
return NULL;
}
return file_name;
}
size_t get_platform_view_file_size()
......@@ -447,24 +447,24 @@ int enlarge_view_file(Obiview_p view, size_t new_size)
int obiview_file_descriptor;
double multiple;
size_t rounded_new_size;
char* file_name;
// TODO if file name changes
// // Create file name
// file_name = build_obiview_file_name(view_name);
// if (file_name == NULL)
// return -1;
// Create file name
file_name = build_obiview_file_name((view->infos)->name);
if (file_name == NULL)
return -1;
// Open view file
obiview_file_descriptor = openat((view->dms)->view_dir_fd, (view->infos)->name, O_RDWR, 0777);
obiview_file_descriptor = openat((view->dms)->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError opening a view file");
// free(file_name);
free(file_name);
return -1;
}
//free(file_name);
free(file_name);
// Round new size to a multiple of page size // TODO make function in utils
multiple = ceil((double) new_size / (double) getpagesize());
......@@ -539,27 +539,26 @@ int write_comments_to_view_file(Obiview_p view, const char* comments)
int create_obiview_file(OBIDMS_p dms, const char* view_name)
{
// char* file_name;
char* file_name;
int obiview_file_descriptor;
size_t file_size;
// TODO
// // Create file name
// file_name = build_obiview_file_name(view_name);
// if (file_name == NULL)
// return -1;
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
// Create file
obiview_file_descriptor = openat(dms->view_dir_fd, view_name, O_RDWR | O_CREAT | O_EXCL, 0777);
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR | O_CREAT | O_EXCL, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError creating an obiview file");
// free(file_name);
free(file_name);
return -1;
}
//free(file_name);
free(file_name);
// Truncate file to the initial size
file_size = get_platform_view_file_size();
......@@ -1104,24 +1103,41 @@ char* view_check_all_predicates(Obiview_p view)
*
**********************************************************************/
bool view_exists(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
char* file_name;
int i;
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
return true;
}
return false;
}
Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments)
{
Obiview_p view;
int i;
index_t line_nb;
struct dirent* dp;
// Check uniqueness of name
while ((dp = readdir(dms->view_directory)) != NULL)
if (view_exists(dms, view_name))
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, view_name) == 0) // TODO change if view name building changes
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nName of new view already exists");
return NULL;
}
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nName of new view already exists");
return NULL;
}
// Allocate memory for view structure
......@@ -1426,28 +1442,27 @@ Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const char* view_
Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
{
// char* file_name;
char* file_name;
Obiview_infos_p view_infos;
int obiview_file_descriptor;
size_t file_size;
// TODO
// // Create file name
// file_name = build_obiview_file_name(view_name);
// if (file_name == NULL)
// return -1;
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
// Open view file
obiview_file_descriptor = openat(dms->view_dir_fd, view_name, O_RDWR, 0777);
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError opening an obiview file");
// free(file_name);
free(file_name);
return NULL;
}
//free(file_name);
free(file_name);
// Get file size
if (read(obiview_file_descriptor, &file_size, sizeof(size_t)) < ((ssize_t) sizeof(size_t)))
......@@ -1481,27 +1496,26 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos)
{
// char* file_name;
char* file_name;
int obiview_file_descriptor;
size_t file_size;
// TODO
// // Get file name
// file_name = build_obiview_file_name(view_name);
// if (file_name == NULL)
// return -1;
// Get file name
file_name = build_obiview_file_name(view_infos->name);
if (file_name == NULL)
return -1;
// Open view file
obiview_file_descriptor = openat(dms->view_dir_fd, view_infos->name, O_RDWR, 0777);
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError opening an obiview file");
// free(file_name);
free(file_name);
return -1;
}
//free(file_name);
free(file_name);
// Unmap the view infos structure
file_size = view_infos->file_size;
......
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