Closes #10 : column groups stored in directories

This commit is contained in:
Celine Mercier
2015-06-23 18:35:34 +02:00
parent 61b6c3ce83
commit 152b34b5f4
10 changed files with 745 additions and 223 deletions

View File

@ -7,15 +7,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include "obidms.h"
#include "obierrno.h"
/************************************************************************
/**************************************************************************
*
* 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
* 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
*
************************************************************************/
**************************************************************************/
/**
@ -33,7 +38,7 @@
* @retvalue NULL if an error occurs
*
* ###Error values
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
*
* @since May 2015
@ -42,11 +47,11 @@
static char *build_directory_name(const char *dms_name);
/***********************************************************************
/************************************************************************
*
* 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
* 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
*
***********************************************************************/
************************************************************************/
static char *build_directory_name(const char *dms_name)
{
@ -71,31 +76,31 @@ static char *build_directory_name(const char *dms_name)
}
/*********************************************************************
/**********************************************************************
*
* 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
* 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
*
*********************************************************************/
**********************************************************************/
int obi_dms_exists(const char* dms_name)
{
struct stat buffer;
char *directory_name;
int exists;
int check_dir;
// Build and check the directory name
directory_name = build_directory_name(dms_name);
if (directory_name == NULL)
return -1;
exists = stat(directory_name, &buffer);
check_dir = stat(directory_name, &buffer);
free(directory_name);
if(exists == 0)
if (check_dir == 0)
return 1;
else // -1
return 0;
else
return 0;
}
@ -108,7 +113,6 @@ OBIDMS_p obi_create_dms(const char* dms_name)
if (directory_name == NULL)
return NULL;
// Try to create the directory
if (mkdir(directory_name, 0x777) < 0)
{
@ -140,24 +144,26 @@ OBIDMS_p obi_open_dms(const char* dms_name)
if (directory_name == NULL)
return NULL;
// try to open the directory
// Try to open the directory
directory = opendir(directory_name);
if (directory == NULL) {
switch (errno) {
case ENOENT:
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
break;
if (directory == NULL)
{
switch (errno)
{
case ENOENT:
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
break;
case EACCES:
obi_set_errno(OBIDMS_ACCESS_ERROR);
break;
case EACCES:
obi_set_errno(OBIDMS_ACCESS_ERROR);
break;
case ENOMEM:
obi_set_errno(OBIDMS_MEMORY_ERROR);
break;
case ENOMEM:
obi_set_errno(OBIDMS_MEMORY_ERROR);
break;
default:
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
default:
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
}
free(directory_name);
return NULL;
@ -165,7 +171,6 @@ OBIDMS_p obi_open_dms(const char* dms_name)
// Allocate the data structure
dms = (OBIDMS_p) malloc(sizeof(OBIDMS_t));
if (dms == NULL)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
@ -178,15 +183,19 @@ OBIDMS_p obi_open_dms(const char* dms_name)
dms->directory = directory;
free(directory_name);
return dms;
}
OBIDMS_p obi_dms(const char* dms_name)
{
int exists = obi_dms_exists(dms_name);
int exists;
switch (exists) {
exists = obi_dms_exists(dms_name);
switch (exists)
{
case 0:
return obi_create_dms(dms_name);
case 1:
@ -194,7 +203,6 @@ OBIDMS_p obi_dms(const char* dms_name)
};
return NULL;
}