2015-09-30 12:03:46 +02:00
|
|
|
/********************************************************************
|
|
|
|
* OBIDMS functions *
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file obidms.c
|
|
|
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
|
|
|
* @date 23 May 2015
|
|
|
|
* @brief OBIDMS functions.
|
2015-05-23 16:29:06 +03:00
|
|
|
*/
|
|
|
|
|
2015-09-30 12:03:46 +02:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2015-06-23 18:35:34 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2015-11-03 14:22:00 +01:00
|
|
|
#include <fcntl.h>
|
2015-06-23 18:35:34 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
2015-06-17 16:51:16 +02:00
|
|
|
|
|
|
|
#include "obidms.h"
|
2015-06-23 18:35:34 +02:00
|
|
|
#include "obierrno.h"
|
2015-07-31 18:03:48 +02:00
|
|
|
#include "obidebug.h"
|
|
|
|
#include "obidmscolumn.h"
|
2015-11-03 14:22:00 +01:00
|
|
|
#include "private_at_functions.h"
|
2015-11-16 14:37:51 +01:00
|
|
|
#include "obilittlebigman.h"
|
2015-07-31 18:03:48 +02:00
|
|
|
|
2015-08-03 15:10:39 +02:00
|
|
|
|
2015-09-30 12:03:46 +02:00
|
|
|
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-05-26 21:36:55 +02:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
/**************************************************************************
|
2015-05-26 21:36:55 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
2015-05-26 21:36:55 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
**************************************************************************/
|
2015-05-26 21:36:55 +02:00
|
|
|
|
|
|
|
|
2015-05-23 16:29:06 +03:00
|
|
|
/**
|
2015-09-30 12:03:46 +02:00
|
|
|
* Internal function building the OBIDMS directory name from an OBIDMS name.
|
2015-05-23 16:29:06 +03:00
|
|
|
*
|
2015-06-10 15:19:02 +02:00
|
|
|
* The function builds the directory name corresponding to an OBIDMS.
|
2015-09-30 12:03:46 +02:00
|
|
|
* It also checks that the name is not too long.
|
2015-05-23 16:29:06 +03:00
|
|
|
*
|
|
|
|
* @warning The returned pointer has to be freed by the caller.
|
|
|
|
*
|
2015-09-30 12:03:46 +02:00
|
|
|
* @param dms_name The name of the OBIDMS.
|
2015-05-23 16:29:06 +03:00
|
|
|
*
|
2015-09-30 12:03:46 +02:00
|
|
|
* @returns A pointer to the directory name.
|
|
|
|
* @retval NULL if an error occurred.
|
2015-05-23 16:29:06 +03:00
|
|
|
*
|
|
|
|
* @since May 2015
|
|
|
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
|
|
|
*/
|
2015-09-30 12:03:46 +02:00
|
|
|
static char* build_directory_name(const char* dms_name);
|
2015-06-17 16:51:16 +02:00
|
|
|
|
|
|
|
|
2015-11-16 14:37:51 +01:00
|
|
|
/**
|
|
|
|
* Internal function building the informations file name from an OBIDMS name.
|
|
|
|
*
|
|
|
|
* The function builds the file name for the informations file of an OBIDMS.
|
|
|
|
*
|
|
|
|
* @warning The returned pointer has to be freed by the caller.
|
|
|
|
*
|
|
|
|
* @param dms_name The name of the OBIDMS.
|
|
|
|
*
|
|
|
|
* @returns A pointer to the file name.
|
|
|
|
* @retval NULL if an error occurred.
|
|
|
|
*
|
|
|
|
* @since November 2015
|
|
|
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
|
|
|
*/
|
|
|
|
static char* build_infos_file_name(const char* dms_name);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function creating the file containing basic informations on the OBIDMS.
|
|
|
|
*
|
|
|
|
* This file contains:
|
|
|
|
* - The endianness of the platform
|
|
|
|
*
|
|
|
|
* @warning The returned pointer has to be freed by the caller.
|
|
|
|
*
|
|
|
|
* @param dms_file_descriptor The file descriptor for the OBIDMS directory.
|
|
|
|
* @param dms_name The name of the OBIDMS.
|
|
|
|
*
|
|
|
|
* @retval 0 if the operation was successfully completed.
|
|
|
|
* @retval -1 if an error occurred.
|
|
|
|
*
|
|
|
|
* @since November 2015
|
|
|
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
|
|
|
*/
|
|
|
|
int create_dms_infos_file(int dms_file_descriptor, const char* dms_name);
|
|
|
|
|
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
/************************************************************************
|
2015-06-17 16:51:16 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
2015-06-17 16:51:16 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
************************************************************************/
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-09-30 12:03:46 +02:00
|
|
|
static char* build_directory_name(const char* dms_name)
|
2015-06-17 16:51:16 +02:00
|
|
|
{
|
2015-09-30 12:03:46 +02:00
|
|
|
char* directory_name;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
|
|
|
// Build the database directory name
|
2015-06-17 16:51:16 +02:00
|
|
|
if (asprintf(&directory_name, "%s.obidms", dms_name) < 0)
|
2015-05-23 16:29:06 +03:00
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
2015-08-03 15:10:39 +02:00
|
|
|
obidebug(1, "\nProblem building an OBIDMS directory name");
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if the database name is not too long
|
2015-06-17 16:51:16 +02:00
|
|
|
if (strlen(directory_name) >= OBIDMS_MAX_NAME)
|
2015-05-23 16:29:06 +03:00
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_LONG_NAME_ERROR);
|
2015-08-03 15:10:39 +02:00
|
|
|
obidebug(1, "\nProblem building an OBIDMS directory name");
|
2015-06-17 16:51:16 +02:00
|
|
|
free(directory_name);
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
return directory_name;
|
2015-05-23 16:29:06 +03:00
|
|
|
}
|
|
|
|
|
2015-06-10 15:19:02 +02:00
|
|
|
|
2015-11-16 14:37:51 +01:00
|
|
|
static char* build_infos_file_name(const char* dms_name)
|
|
|
|
{
|
|
|
|
char* file_name;
|
|
|
|
|
|
|
|
// Build file name
|
|
|
|
if (asprintf(&file_name, "%s_infos", dms_name) < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
|
|
obidebug(1, "\nProblem building an informations file name");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int create_dms_infos_file(int dms_file_descriptor, const char* dms_name)
|
|
|
|
{
|
|
|
|
char* file_name;
|
|
|
|
int infos_file_descriptor;
|
|
|
|
off_t file_size;
|
|
|
|
bool little_endian;
|
|
|
|
|
|
|
|
file_size = sizeof(bool);
|
|
|
|
|
|
|
|
// Create file name
|
|
|
|
file_name = build_infos_file_name(dms_name);
|
|
|
|
if (file_name == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// Create file
|
|
|
|
infos_file_descriptor = openat(dms_file_descriptor, file_name, O_RDWR | O_CREAT | O_EXCL, 0777);
|
|
|
|
if (infos_file_descriptor < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError creating an informations file");
|
|
|
|
free(file_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(file_name);
|
|
|
|
|
|
|
|
// Truncate the infos file to the right size
|
|
|
|
if (ftruncate(infos_file_descriptor, file_size) < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError truncating an informations file");
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write endianness
|
|
|
|
little_endian = obi_is_little_endian();
|
|
|
|
if (write(infos_file_descriptor, &little_endian, sizeof(bool)) < ((ssize_t) sizeof(bool)))
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError writing the endianness in an informations file");
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close file
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
/**********************************************************************
|
2015-05-26 21:36:55 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
2015-05-26 21:36:55 +02:00
|
|
|
*
|
2015-06-23 18:35:34 +02:00
|
|
|
**********************************************************************/
|
2015-05-26 21:36:55 +02:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
int obi_dms_exists(const char* dms_name)
|
|
|
|
{
|
2015-05-26 21:36:55 +02:00
|
|
|
struct stat buffer;
|
2015-06-17 16:51:16 +02:00
|
|
|
char *directory_name;
|
2015-06-23 18:35:34 +02:00
|
|
|
int check_dir;
|
2015-05-26 21:36:55 +02:00
|
|
|
|
|
|
|
// Build and check the directory name
|
2015-06-17 16:51:16 +02:00
|
|
|
directory_name = build_directory_name(dms_name);
|
|
|
|
if (directory_name == NULL)
|
2015-05-26 21:36:55 +02:00
|
|
|
return -1;
|
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
check_dir = stat(directory_name, &buffer);
|
2015-05-26 21:36:55 +02:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
free(directory_name);
|
2015-05-26 21:36:55 +02:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
if (check_dir == 0)
|
2015-05-26 21:36:55 +02:00
|
|
|
return 1;
|
2015-06-23 18:35:34 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2015-05-26 21:36:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
OBIDMS_p obi_create_dms(const char* dms_name)
|
|
|
|
{
|
2015-11-03 14:22:00 +01:00
|
|
|
char* directory_name;
|
2015-11-16 14:37:51 +01:00
|
|
|
DIR* dms_dir;
|
|
|
|
int dms_file_descriptor;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
|
|
|
// Build and check the directory name
|
2015-06-17 16:51:16 +02:00
|
|
|
directory_name = build_directory_name(dms_name);
|
|
|
|
if (directory_name == NULL)
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Try to create the directory
|
2015-09-21 15:48:02 +02:00
|
|
|
if (mkdir(directory_name, 00777) < 0)
|
2015-05-23 16:29:06 +03:00
|
|
|
{
|
2015-06-17 16:51:16 +02:00
|
|
|
if (errno == EEXIST)
|
2015-11-09 15:22:01 +01:00
|
|
|
{
|
2015-05-23 16:29:06 +03:00
|
|
|
obi_set_errno(OBIDMS_EXIST_ERROR);
|
2015-11-09 15:22:01 +01:00
|
|
|
obidebug(1, "\nAn OBIDMS directory with the same name already exists in this directory.");
|
|
|
|
}
|
2015-05-23 16:29:06 +03:00
|
|
|
else
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
2015-08-03 15:10:39 +02:00
|
|
|
obidebug(1, "\nProblem creating an OBIDMS directory");
|
2015-06-17 16:51:16 +02:00
|
|
|
free(directory_name);
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-03 14:22:00 +01:00
|
|
|
// Get file descriptor of DMS directory to create the arrays directory
|
|
|
|
dms_dir = opendir(directory_name);
|
|
|
|
if (dms_dir == NULL)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nProblem opening a newly created OBIDMS directory");
|
|
|
|
free(directory_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-11-09 11:22:51 +01:00
|
|
|
|
|
|
|
free(directory_name);
|
|
|
|
|
2015-11-03 14:22:00 +01:00
|
|
|
dms_file_descriptor = dirfd(dms_dir);
|
|
|
|
if (dms_file_descriptor < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nProblem getting the file descriptor of a newly created OBIDMS directory");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the arrays directory
|
2015-11-16 14:37:51 +01:00
|
|
|
if (mkdirat(dms_file_descriptor, ARRAYS_DIR_NAME, 00777) < 0)
|
2015-11-03 14:22:00 +01:00
|
|
|
{
|
|
|
|
obi_set_errno(OBI_ARRAY_ERROR);
|
|
|
|
obidebug(1, "\nProblem creating an arrays directory");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:37:51 +01:00
|
|
|
// Create the informations file
|
|
|
|
if (create_dms_infos_file(dms_file_descriptor, dms_name) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
return obi_open_dms(dms_name);
|
2015-05-23 16:29:06 +03:00
|
|
|
}
|
|
|
|
|
2015-06-10 15:19:02 +02:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
OBIDMS_p obi_open_dms(const char* dms_name)
|
|
|
|
{
|
|
|
|
OBIDMS_p dms;
|
|
|
|
char* directory_name;
|
2015-11-16 14:37:51 +01:00
|
|
|
char* infos_file_name;
|
|
|
|
int infos_file_descriptor;
|
|
|
|
bool little_endian_dms;
|
|
|
|
bool little_endian_platform;
|
2015-06-17 16:51:16 +02:00
|
|
|
|
|
|
|
dms = NULL;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-11-09 15:06:02 +01:00
|
|
|
// Allocate the data structure
|
|
|
|
dms = (OBIDMS_p) malloc(sizeof(OBIDMS_t));
|
|
|
|
if (dms == NULL)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
|
|
obidebug(1, "\nError allocating the memory for the OBIDMS structure");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-23 16:29:06 +03:00
|
|
|
// Build and check the directory name
|
2015-06-17 16:51:16 +02:00
|
|
|
directory_name = build_directory_name(dms_name);
|
|
|
|
if (directory_name == NULL)
|
2015-11-09 15:06:02 +01:00
|
|
|
{
|
|
|
|
free(dms);
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
2015-11-09 15:06:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(dms->directory_name, directory_name, OBIDMS_MAX_NAME);
|
|
|
|
free(directory_name);
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
// Try to open the directory
|
2015-11-09 15:06:02 +01:00
|
|
|
dms->directory = opendir(dms->directory_name);
|
|
|
|
if (dms->directory == NULL)
|
2015-06-23 18:35:34 +02:00
|
|
|
{
|
|
|
|
switch (errno)
|
|
|
|
{
|
|
|
|
case ENOENT:
|
|
|
|
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
|
|
|
|
break;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
case EACCES:
|
|
|
|
obi_set_errno(OBIDMS_ACCESS_ERROR);
|
|
|
|
break;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
case ENOMEM:
|
|
|
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
|
|
break;
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
default:
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
2015-05-23 16:29:06 +03:00
|
|
|
}
|
2015-08-03 15:10:39 +02:00
|
|
|
obidebug(1, "\nCan't open OBIDMS directory");
|
2015-11-09 15:06:02 +01:00
|
|
|
free(dms);
|
2015-05-23 16:29:06 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:37:51 +01:00
|
|
|
// Get and store file descriptor of DMS directory to open the informations file
|
2015-11-09 15:06:02 +01:00
|
|
|
dms->dir_fd = dirfd(dms->directory);
|
|
|
|
if (dms->dir_fd < 0)
|
2015-11-03 14:22:00 +01:00
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError getting the file descriptor for a newly created OBIDMS directory");
|
2015-11-09 15:06:02 +01:00
|
|
|
closedir(dms->directory);
|
|
|
|
free(dms);
|
2015-11-03 14:22:00 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:37:51 +01:00
|
|
|
// Open informations file to check endianness
|
|
|
|
infos_file_name = build_infos_file_name(dms_name);
|
|
|
|
infos_file_descriptor = openat(dms->dir_fd, infos_file_name, O_RDONLY, 0777);
|
|
|
|
if (infos_file_descriptor < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError opening an informations file");
|
|
|
|
closedir(dms->directory);
|
|
|
|
free(dms);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(infos_file_name);
|
|
|
|
|
|
|
|
// Check endianness of the platform and DMS
|
|
|
|
little_endian_platform = obi_is_little_endian();
|
|
|
|
if (read(infos_file_descriptor, &little_endian_dms, sizeof(bool)) < ((ssize_t) sizeof(bool)))
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError reading the endianness in an informations file");
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
closedir(dms->directory);
|
|
|
|
free(dms);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (little_endian_platform != little_endian_dms)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
|
|
|
obidebug(1, "\nError: The DMS and the platform have different endianness");
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
closedir(dms->directory);
|
|
|
|
free(dms);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(infos_file_descriptor);
|
|
|
|
|
2015-11-03 14:22:00 +01:00
|
|
|
// Open the arrays directory
|
2015-11-16 14:37:51 +01:00
|
|
|
dms->array_directory = private_opendirat(dms->dir_fd, ARRAYS_DIR_NAME);
|
2015-11-03 14:22:00 +01:00
|
|
|
if (dms->array_directory == NULL)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError opening the arrays directory");
|
2015-11-09 15:06:02 +01:00
|
|
|
closedir(dms->directory);
|
|
|
|
free(dms);
|
2015-11-03 14:22:00 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 15:06:02 +01:00
|
|
|
// Store the array directory's file descriptor
|
|
|
|
dms->array_dir_fd = dirfd(dms->array_directory);
|
|
|
|
if (dms->array_dir_fd < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
2015-11-16 14:37:51 +01:00
|
|
|
obidebug(1, "\nError getting the file descriptor of the arrays directory");
|
2015-11-09 15:06:02 +01:00
|
|
|
closedir(dms->array_directory);
|
2015-11-16 14:37:51 +01:00
|
|
|
closedir(dms->directory);
|
2015-11-09 15:06:02 +01:00
|
|
|
free(dms);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-06-23 18:35:34 +02:00
|
|
|
|
2015-05-23 16:29:06 +03:00
|
|
|
return dms;
|
|
|
|
}
|
|
|
|
|
2015-06-10 15:19:02 +02:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
OBIDMS_p obi_dms(const char* dms_name)
|
|
|
|
{
|
2015-06-23 18:35:34 +02:00
|
|
|
int exists;
|
2015-05-26 21:36:55 +02:00
|
|
|
|
2015-06-23 18:35:34 +02:00
|
|
|
exists = obi_dms_exists(dms_name);
|
|
|
|
|
|
|
|
switch (exists)
|
|
|
|
{
|
2015-05-26 21:36:55 +02:00
|
|
|
case 0:
|
2015-06-17 16:51:16 +02:00
|
|
|
return obi_create_dms(dms_name);
|
2015-05-26 21:36:55 +02:00
|
|
|
case 1:
|
2015-06-17 16:51:16 +02:00
|
|
|
return obi_open_dms(dms_name);
|
2015-05-26 21:36:55 +02:00
|
|
|
};
|
|
|
|
|
2015-08-03 15:10:39 +02:00
|
|
|
obidebug(1, "\nError checking if an OBIDMS directory exists");
|
2015-05-26 21:36:55 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-23 16:29:06 +03:00
|
|
|
|
2015-06-17 16:51:16 +02:00
|
|
|
int obi_close_dms(OBIDMS_p dms)
|
|
|
|
{
|
2015-05-23 16:29:06 +03:00
|
|
|
if (dms != NULL)
|
|
|
|
{
|
|
|
|
if (closedir(dms->directory) < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
2015-11-03 14:22:00 +01:00
|
|
|
obidebug(1, "\nError closing an OBIDMS directory");
|
|
|
|
free(dms);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (closedir(dms->array_directory) < 0)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBI_ARRAY_ERROR);
|
|
|
|
obidebug(1, "\nError closing an array directory");
|
2015-05-23 16:29:06 +03:00
|
|
|
free(dms);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(dms);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|