Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
152b34b5
Commit
152b34b5
authored
Jun 23, 2015
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes
#10
: column groups stored in directories
parent
61b6c3ce
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
745 additions
and
223 deletions
+745
-223
python/obitools3/obidms/capidms.cfiles
python/obitools3/obidms/capidms.cfiles
+2
-2
python/obitools3/obidms/capidms.pxd
python/obitools3/obidms/capidms.pxd
+3
-3
python/obitools3/obidms/obidmscolumn/capidmscolumn.cfiles
python/obitools3/obidms/obidmscolumn/capidmscolumn.cfiles
+4
-2
src/obidms.c
src/obidms.c
+42
-34
src/obidms.h
src/obidms.h
+5
-6
src/obidmscolumn.c
src/obidmscolumn.c
+213
-144
src/obidmscolumn.h
src/obidmscolumn.h
+29
-28
src/obidmscolumngroup.c
src/obidmscolumngroup.c
+283
-0
src/obidmscolumngroup.h
src/obidmscolumngroup.h
+158
-0
src/obitypes.c
src/obitypes.c
+6
-4
No files found.
python/obitools3/obidms/capidms.cfiles
View file @
152b34b5
...
...
@@ -6,5 +6,5 @@
../../../src/obilittlebigman.c
../../../src/obitypes.h
../../../src/obitypes.c
../../../src/private_
openat
.h
../../../src/private_
openat
.c
../../../src/private_
at_functions
.h
../../../src/private_
at_functions
.c
python/obitools3/obidms/capidms.pxd
View file @
152b34b5
...
...
@@ -16,11 +16,11 @@ cdef extern from "obidms.h" nogil:
ctypedef
OBIDMS_t
*
OBIDMS_p
OBIDMS_p
obi_create_dms
(
const_char_p
name
)
OBIDMS_p
obi_create_dms
(
const_char_p
dms_
name
)
OBIDMS_p
obi_open_dms
(
const_char_p
name
)
OBIDMS_p
obi_open_dms
(
const_char_p
dms_
name
)
OBIDMS_p
obi_dms
(
const_char_p
name
)
OBIDMS_p
obi_dms
(
const_char_p
dms_
name
)
int
obi_close_dms
(
OBIDMS_p
dms
)
...
...
python/obitools3/obidms/obidmscolumn/capidmscolumn.cfiles
View file @
152b34b5
../../../../src/obidmscolumn.h
../../../../src/obidmscolumn.c
../../../../src/obidmscolumngroup.h
../../../../src/obidmscolumngroup.c
../../../../src/obidms.h
../../../../src/obidms.c
../../../../src/obierrno.h
...
...
@@ -8,5 +10,5 @@
../../../../src/obilittlebigman.c
../../../../src/obitypes.h
../../../../src/obitypes.c
../../../../src/private_
openat
.h
../../../../src/private_
openat
.c
../../../../src/private_
at_functions
.h
../../../../src/private_
at_functions
.c
src/obidms.c
View file @
152b34b5
...
...
@@ -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 occur
r
ed 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
;
//
t
ry to open the directory
//
T
ry 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
;
}
...
...
src/obidms.h
View file @
152b34b5
...
...
@@ -41,12 +41,12 @@ typedef struct OBIDMS {
*
* @param dms_name a pointer to a C string containing the name of the database.
* The actual directory name used to store the DMS will be
* `<name>.obidms`.
* `<
dms_
name>.obidms`.
*
* @return an integer value indicating the status of the database
* @retvalue 1 the database exist
* @retvalue 0 the database does not exist
* @retvalue -1 an error occured
* @retvalue -1 an error occur
r
ed
*
* @see obi_close_dms()
* @since May 2015
...
...
@@ -72,7 +72,7 @@ int obi_dms_exists(const char* dms_name);
* ###Error values
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
* - OBIDMS_MEMORY_ERROR : something wrong occur
r
ed during memory allocation.
*
* @see obi_close_dms()
* @since May 2015
...
...
@@ -92,9 +92,8 @@ OBIDMS_p obi_create_dms(const char *dms_name);
* @retval NULL on error and the `obi_errno`variable is set.
*
* ###Error values
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
* - OBIDMS_MEMORY_ERROR : something wrong occur
r
ed during memory allocation.
*
* @see obi_close_dms()
* @since May 2015
...
...
@@ -118,7 +117,7 @@ OBIDMS_p obi_open_dms(const char *dms_name);
*
* ###Error values
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
* - OBIDMS_MEMORY_ERROR : something wrong occur
r
ed during memory allocation.
*
* @see obi_close_dms()
* @since May 2015
...
...
src/obidmscolumn.c
View file @
152b34b5
This diff is collapsed.
Click to expand it.
src/obidmscolumn.h
View file @
152b34b5
...
...
@@ -22,11 +22,9 @@
#include "obitypes.h"
#include "obierrno.h"
#include "obilittlebigman.h"
#include "obidmscolumngroup.h"
#define OBIDMS_MAX_COLNAME (128)
/**< The maximum length of an OBIDMS column name
*/
typedef
int32_t
obiversion_t
;
/**< Used to store the column version number
*/
...
...
@@ -35,7 +33,7 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
*/
typedef
struct
OBIDMS_column_header
{
bool
little_endian
;
/**< endianess of the column:
bool
little_endian
;
/**< endian
n
ess of the column:
- `true` on little endian platforms
- `false` on big endian platforms
...
...
@@ -57,6 +55,7 @@ typedef struct OBIDMS_column_header {
*/
}
OBIDMS_column_header_t
,
*
OBIDMS_column_header_p
;
/**
* @brief Structure describing a Column of the OBITools DMS
*
...
...
@@ -64,25 +63,27 @@ typedef struct OBIDMS_column_header {
* creating, opening or cloning an OBIDMS_column.
*/
typedef
struct
OBIDMS_column
{
OBIDMS_p
dms
;
/**< A pointer to a DMS instance
*/
OBIDMS_column_header_p
header
;
/**< A pointer to the header of the column
*/
void
*
data
;
/**< A `void` pointer to the beginning of the
* data.
*
* @warning never use this member directly
* outside of the code of the
* low level functions
* of the OBITools DMS
*/
bool
writable
;
/**< Indicates if the column is writable or not.
* - `true` the column is writable
* - `false` the column is read-only
*
* A column is writable only by its creator
* until it closes it.
*/
OBIDMS_p
dms
;
/**< A pointer to a DMS instance
*/
OBIDMS_column_group_p
column_group
;
/**< A pointer to an OBIDMS column group instance
*/
OBIDMS_column_header_p
header
;
/**< A pointer to the header of the column
*/
void
*
data
;
/**< A `void` pointer to the beginning of the
* data.
*
* @warning never use this member directly
* outside of the code of the
* low level functions
* of the OBITools DMS
*/
bool
writable
;
/**< Indicates if the column is writable or not.
* - `true` the column is writable
* - `false` the column is read-only
*
* A column is writable only by its creator
* until it closes it.
*/
}
OBIDMS_column_t
,
*
OBIDMS_column_p
;
...
...
@@ -103,7 +104,7 @@ size_t obi_get_platform_header_size();
/**
* @brief Creates a column.
*
* @param dms a pointer
as returned by obi_create_dms() or obi_open_dms()
* @param dms a pointer
on an OBIDMS column
* @param column_name the name of the new column
* @param type the OBIType code used to create the column
* @param nb_elements the number of elements to be stored
...
...
@@ -112,9 +113,9 @@ size_t obi_get_platform_header_size();
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_column_p
obi_create_column
(
OBIDMS_p
dms
,
char
*
column_name
,
OBIType_t
type
,
size_t
nb_elements
);
const
char
*
column_name
,
OBIType_t
type
,
size_t
nb_elements
);
/**
...
...
@@ -126,7 +127,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
* @return the bigger version number used for this column
* @return -1 if the column does not exist
*/
obiversion_t
obi_get_latest_version_number
(
OBIDMS_
p
dms
,
char
*
column_name
);
obiversion_t
obi_get_latest_version_number
(
OBIDMS_
column_group_p
column_group
);
#endif
/* OBIDMSCOLUMN_H_ */
src/obidmscolumngroup.c
0 → 100644
View file @
152b34b5
/****************************************************************************
* OBIDMS column groups functions *
****************************************************************************/
/**
* @file obidmscolumngroup.c
* @author Celine Mercier
* @date 18 June 2015
* @brief Functions for OBIDMS column groups.
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include "obidmscolumngroup.h"
#include "obidms.h"
#include "private_at_functions.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
*
**************************************************************************/
/**
* Internal function building the group directory name from an OBIDMS column name.
*
* The function builds the directory name corresponding to an OBIDMS column group.
* It checks also that the name is not too long.
*
* @warning The returned pointer has to be freed by the caller.
*
* @param column_name the name of the OBIDMS column
*
* @return a pointer to the OBIDMS column directory name
* @retvalue <column_directory_name> if everything is ok
* @retvalue NULL if an error occurs
*
* ###Error values
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
*
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static
char
*
build_column_directory_name
(
const
char
*
column_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
*
************************************************************************/
static
char
*
build_column_directory_name
(
const
char
*
column_name
)
{
char
*
column_directory_name
;
// Build the database directory name
if
(
asprintf
(
&
column_directory_name
,
"%s.obicol"
,
column_name
)
<
0
)
{
obi_set_errno
(
OBICOLDIR_MEMORY_ERROR
);
return
NULL
;
}
// Test if the database name is not too long
if
(
strlen
(
column_directory_name
)
>=
OBIDMS_COLUMN_DIR_MAX_NAME
)
{
obi_set_errno
(
OBICOLDIR_LONG_NAME_ERROR
);
free
(
column_directory_name
);
return
NULL
;
}
return
column_directory_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
*
**********************************************************************/
int
obi_column_group_exists
(
OBIDMS_p
dms
,
const
char
*
column_name
)
{
struct
stat
buffer
;
char
*
column_directory_name
;
char
*
full_path
;
int
check_dir
;
int
dms_file_descriptor
;
// Build and check the directory name
column_directory_name
=
build_column_directory_name
(
column_name
);
if
(
column_directory_name
==
NULL
)
{
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
return
-
1
;
}
// Get the file descriptor for the dms
dms_file_descriptor
=
dirfd
(
dms
->
directory
);
if
(
dms_file_descriptor
<
0
)
{
obi_set_errno
(
OBIDMS_UNKNOWN_ERROR
);
free
(
column_directory_name
);
return
-
1
;
}
// Get the full path for the column directory
full_path
=
get_full_path
(
dms_file_descriptor
,
column_directory_name
);
if
(
full_path
==
NULL
)
{
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
free
(
column_directory_name
);
return
-
1
;
}
check_dir
=
stat
(
full_path
,
&
buffer
);
free
(
column_directory_name
);
free
(
full_path
);
//close(dms_file_descriptor);
if
(
check_dir
==
0
)
return
1
;
else
return
0
;
}
OBIDMS_column_group_p
obi_create_column_group
(
OBIDMS_p
dms
,
const
char
*
column_name
)
{
char
*
column_directory_name
;
int
dms_file_descriptor
;
// Build and check the directory name
column_directory_name
=
build_column_directory_name
(
column_name
);
if
(
column_directory_name
==
NULL
)
{
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
return
NULL
;
}
// Get the file descriptor for the dms
dms_file_descriptor
=
dirfd
(
dms
->
directory
);
if
(
dms_file_descriptor
<
0
)
{
obi_set_errno
(
OBIDMS_UNKNOWN_ERROR
);
free
(
column_directory_name
);
return
NULL
;
}
// Try to create the directory
if
(
private_mkdirat
(
dms_file_descriptor
,
column_directory_name
,
0x777
)
<
0
)
{
if
(
errno
==
EEXIST
)
obi_set_errno
(
OBICOLDIR_EXIST_ERROR
);
else
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
free
(
column_directory_name
);
close
(
dms_file_descriptor
);
return
NULL
;
}
free
(
column_directory_name
);
//close(dms_file_descriptor);
return
obi_open_column_group
(
dms
,
column_name
);
}
OBIDMS_column_group_p
obi_open_column_group
(
OBIDMS_p
dms
,
const
char
*
column_name
)
{
OBIDMS_column_group_p
column_group
;
char
*
column_directory_name
;
DIR
*
directory
;
int
dms_file_descriptor
;
column_group
=
NULL
;
// Build and check the directory name
column_directory_name
=
build_column_directory_name
(
column_name
);
if
(
column_directory_name
==
NULL
)
return
NULL
;
// Get the file descriptor for the dms
dms_file_descriptor
=
dirfd
(
dms
->
directory
);
if
(
dms_file_descriptor
<
0
)
{
obi_set_errno
(
OBIDMS_UNKNOWN_ERROR
);
free
(
column_directory_name
);
return
NULL
;
}
// Try to open the column directory
directory
=
private_opendirat
(
dms_file_descriptor
,
column_directory_name
);
if
(
directory
==
NULL
)
{
switch
(
errno
)
{
case
ENOENT
:
obi_set_errno
(
OBICOLDIR_NOT_EXIST_ERROR
);
break
;
case
EACCES
:
obi_set_errno
(
OBICOLDIR_ACCESS_ERROR
);
break
;
case
ENOMEM
:
obi_set_errno
(
OBICOLDIR_MEMORY_ERROR
);
break
;
default:
obi_set_errno
(
OBICOLDIR_UNKNOWN_ERROR
);
}
free
(
column_directory_name
);
close
(
dms_file_descriptor
);
return
NULL
;
}
// Allocate the column dir structure
column_group
=
(
OBIDMS_column_group_p
)
malloc
(
sizeof
(
OBIDMS_column_group_t
));
if
(
column_group
==
NULL
)
{
obi_set_errno
(
OBICOLDIR_MEMORY_ERROR
);
free
(
column_directory_name
);
close
(
dms_file_descriptor
);
return
NULL
;
}
// Initialize the data structure
strcpy
(
column_group
->
directory_name
,
column_directory_name
);
strcpy
(
column_group
->
column_name
,
column_name
);
column_group
->
directory
=
directory
;
free
(
column_directory_name
);
//close(dms_file_descriptor);
return
column_group
;
}
OBIDMS_column_group_p
obi_column_group
(
OBIDMS_p
dms
,
const
char
*
column_name
)
{
int
exists
;
exists
=
obi_column_group_exists
(
dms
,
column_name
);
switch
(
exists
)
{
case
0
:
return
obi_create_column_group
(
dms
,
column_name
);
case
1
:
return
obi_open_column_group
(
dms
,
column_name
);
};
return
NULL
;
}
int
obi_close_column_group
(
OBIDMS_column_group_p
column_group
)
{
if
(
column_group
!=
NULL
)
{
// Close the column directory
if
(
closedir
(
column_group
->
directory
)
<
0
)
{
obi_set_errno
(
OBICOLDIR_MEMORY_ERROR
);
free
(
column_group
);
return
-
1
;
}
free
(
column_group
);
}
return
0
;
}
src/obidmscolumngroup.h
0 → 100644
View file @
152b34b5
/****************************************************************************
* OBIDMS column directories header file *