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
a32920e4
Commit
a32920e4
authored
Apr 29, 2016
by
Celine Mercier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relative paths when creating or opening a DMS now work
parent
31cf27d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
35 deletions
+73
-35
src/obidms.c
src/obidms.c
+49
-26
src/obidms.h
src/obidms.h
+24
-9
No files found.
src/obidms.c
View file @
a32920e4
...
...
@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include "obidms.h"
#include "obierrno.h"
...
...
@@ -202,14 +203,14 @@ int create_dms_infos_file(int dms_file_descriptor, const char* dms_name)
*
**********************************************************************/
int
obi_dms_exists
(
const
char
*
dms_
name
)
int
obi_dms_exists
(
const
char
*
dms_
path
)
{
struct
stat
buffer
;
char
*
directory_name
;
int
check_dir
;
// Build and check the directory name
directory_name
=
build_directory_name
(
dms_
name
);
directory_name
=
build_directory_name
(
dms_
path
);
if
(
directory_name
==
NULL
)
return
-
1
;
...
...
@@ -224,14 +225,15 @@ int obi_dms_exists(const char* dms_name)
}
OBIDMS_p
obi_create_dms
(
const
char
*
dms_
name
)
OBIDMS_p
obi_create_dms
(
const
char
*
dms_
path
)
{
char
*
directory_name
;
DIR
*
dms_dir
;
int
dms_file_descriptor
;
char
*
directory_name
;
DIR
*
dms_dir
;
int
dms_file_descriptor
;
size_t
i
,
j
;
// Build and check the directory name
directory_name
=
build_directory_name
(
dms_
name
);
directory_name
=
build_directory_name
(
dms_
path
);
if
(
directory_name
==
NULL
)
return
NULL
;
...
...
@@ -278,22 +280,32 @@ OBIDMS_p obi_create_dms(const char* dms_name)
return
NULL
;
}
// Isolate the dms name
j
=
0
;
for
(
i
=
0
;
i
<
strlen
(
dms_path
);
i
++
)
{
if
(
dms_path
[
i
]
==
'/'
)
j
=
i
+
1
;
i
++
;
}
// Create the informations file
if
(
create_dms_infos_file
(
dms_file_descriptor
,
dms_
name
)
<
0
)
if
(
create_dms_infos_file
(
dms_file_descriptor
,
dms_
path
+
j
)
<
0
)
return
NULL
;
return
obi_open_dms
(
dms_
name
);
return
obi_open_dms
(
dms_
path
);
}
OBIDMS_p
obi_open_dms
(
const
char
*
dms_
name
)
OBIDMS_p
obi_open_dms
(
const
char
*
dms_
path
)
{
OBIDMS_p
dms
;
char
*
directory_name
;
char
*
relative_directory_path
;
char
*
infos_file_name
;
int
infos_file_descriptor
;
bool
little_endian_dms
;
bool
little_endian_platform
;
size_t
i
,
j
;
dms
=
NULL
;
...
...
@@ -307,18 +319,37 @@ OBIDMS_p obi_open_dms(const char* dms_name)
}
// Build and check the directory name
directory_name
=
build_directory_name
(
dms_name
);
if
(
directory_name
==
NULL
)
relative_directory_path
=
build_directory_name
(
dms_path
);
if
(
relative_directory_path
==
NULL
)
{
free
(
dms
);
return
NULL
;
}
strncpy
(
dms
->
directory_name
,
directory_name
,
OBIDMS_MAX_NAME
);
free
(
directory_name
);
// Build and store the absolute path to the DMS
if
(
getcwd
(
dms
->
directory_path
,
MAX_PATH_LEN
)
==
NULL
)
{
obi_set_errno
(
OBIDMS_UNKNOWN_ERROR
);
obidebug
(
1
,
"
\n
Error getting the absolute path to the current working directory"
);
free
(
relative_directory_path
);
return
NULL
;
}
strcat
(
dms
->
directory_path
,
"/"
);
strcat
(
dms
->
directory_path
,
relative_directory_path
);
free
(
relative_directory_path
);
// Isolate and store the dms name
j
=
0
;
for
(
i
=
0
;
i
<
strlen
(
dms_path
);
i
++
)
{
if
(
dms_path
[
i
]
==
'/'
)
j
=
i
+
1
;
i
++
;
}
strcpy
(
dms
->
dms_name
,
dms_path
+
j
);
// Try to open the directory
dms
->
directory
=
opendir
(
dms
->
directory_
name
);
dms
->
directory
=
opendir
(
dms
->
directory_
path
);
if
(
dms
->
directory
==
NULL
)
{
switch
(
errno
)
...
...
@@ -355,7 +386,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
}
// Open informations file to check endianness
infos_file_name
=
build_infos_file_name
(
dms_name
);
infos_file_name
=
build_infos_file_name
(
dms
->
dms
_name
);
infos_file_descriptor
=
openat
(
dms
->
dir_fd
,
infos_file_name
,
O_RDONLY
,
0777
);
if
(
infos_file_descriptor
<
0
)
{
...
...
@@ -602,15 +633,7 @@ char* obi_dms_get_dms_path(OBIDMS_p dms)
return
NULL
;
}
if
(
getcwd
(
full_path
,
MAX_PATH_LEN
)
==
NULL
)
// TODO store when opening
{
obi_set_errno
(
OBI_UTILS_ERROR
);
obidebug
(
1
,
"
\n
Error getting the path to a file or directory"
);
return
NULL
;
}
strcat
(
full_path
,
"/"
);
strcat
(
full_path
,
dms
->
directory_name
);
strcpy
(
full_path
,
dms
->
directory_path
);
return
full_path
;
}
...
...
src/obidms.h
View file @
a32920e4
...
...
@@ -78,9 +78,14 @@ typedef struct Opened_indexers_list {
* and opening of an OBITools Data Management System (DMS)
*/
typedef
struct
OBIDMS
{
char
dms_name
[
OBIDMS_MAX_NAME
+
1
];
/** The name of the DMS.
*/
char
directory_name
[
OBIDMS_MAX_NAME
+
1
];
/**< The name of the directory
* containing the DMS.
*/
char
directory_path
[
MAX_PATH_LEN
];
/**< The absolute path of the directory
* containing the DMS.
*/
DIR
*
directory
;
/**< A directory entry usable to
* refer and scan the database directory.
*/
...
...
@@ -105,7 +110,7 @@ typedef struct OBIDMS {
/**
* @brief Checks if an OBIDMS exists.
*
* @param dms_
name A pointer to a C string containing the name of
the database.
* @param dms_
path A pointer to a C string containing the path to
the database.
*
* @returns An integer value indicating the status of the database.
* @retval 1 if the database exists.
...
...
@@ -115,7 +120,7 @@ typedef struct OBIDMS {
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
int
obi_dms_exists
(
const
char
*
dms_
name
);
int
obi_dms_exists
(
const
char
*
dms_
path
);
/**
...
...
@@ -127,7 +132,7 @@ int obi_dms_exists(const char* dms_name);
*
* A directory to store Obiblob indexers is also created.
*
* @param dms_
name A pointer to a C string containing the name of
the database.
* @param dms_
path A pointer to a C string containing the path to
the database.
* The actual directory name used to store the DMS will be
* `<dms_name>.obidms`.
*
...
...
@@ -144,7 +149,7 @@ OBIDMS_p obi_create_dms(const char* dms_name);
/**
* @brief Opens an existing OBITools Data Management instance (OBIDMS).
*
* @param dms_
name A pointer to a C string containing the name of
the database.
* @param dms_
path A pointer to a C string containing the path to
the database.
*
* @returns A pointer to an OBIDMS structure describing the opened DMS.
* @retval NULL if an error occurred.
...
...
@@ -153,7 +158,7 @@ OBIDMS_p obi_create_dms(const char* dms_name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p
obi_open_dms
(
const
char
*
dms_
name
);
OBIDMS_p
obi_open_dms
(
const
char
*
dms_
path
);
/**
...
...
@@ -162,7 +167,7 @@ OBIDMS_p obi_open_dms(const char* dms_name);
* If the database already exists, this function opens it, otherwise it
* creates a new database.
*
* @param dms_
name A pointer to a C string containing the name of
the database.
* @param dms_
path A pointer to a C string containing the path to
the database.
*
* @returns A pointer to an OBIDMS structure describing the OBIDMS.
* @retval NULL if an error occurred.
...
...
@@ -171,7 +176,7 @@ OBIDMS_p obi_open_dms(const char* dms_name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
OBIDMS_p
obi_dms
(
const
char
*
dms_
name
);
OBIDMS_p
obi_dms
(
const
char
*
dms_
path
);
/**
...
...
@@ -295,9 +300,19 @@ int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
/**
* Function meant to disappear soon
* @brief Gets the full path to the DMS.
*
* @warning The returned pointer has to be freed by the caller.
*
* @param dms The DMS.
*
* @returns A pointer to the full path.
* @retval NULL if an error occurred.
*
* @since April 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
char
*
obi_dms_get_path
(
OBIDMS_p
dms
);
char
*
obi_dms_get_
dms_
path
(
OBIDMS_p
dms
);
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment