Commit 41f62709 by celinemercier

Error handling: obidebug() with message for all errors, and removed

commands closing directories when an error occurred (creating more
errors).
parent 1e01c905
......@@ -17,6 +17,7 @@
#include "obidebug.h"
#include "obidmscolumn.h"
#define DEBUG_LEVEL 0
......@@ -65,6 +66,7 @@ static char *build_directory_name(const char *dms_name)
if (asprintf(&directory_name, "%s.obidms", dms_name) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nProblem building an OBIDMS directory name");
return NULL;
}
......@@ -72,6 +74,7 @@ static char *build_directory_name(const char *dms_name)
if (strlen(directory_name) >= OBIDMS_MAX_NAME)
{
obi_set_errno(OBIDMS_LONG_NAME_ERROR);
obidebug(1, "\nProblem building an OBIDMS directory name");
free(directory_name);
return NULL;
}
......@@ -124,7 +127,7 @@ OBIDMS_p obi_create_dms(const char* dms_name)
obi_set_errno(OBIDMS_EXIST_ERROR);
else
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
obidebug(1, "\nProblem creating an OBIDMS directory");
free(directory_name);
return NULL;
}
......@@ -152,7 +155,6 @@ OBIDMS_p obi_open_dms(const char* dms_name)
directory = opendir(directory_name);
if (directory == NULL)
{
obidebug(1, "Can't open DMS");
switch (errno)
{
case ENOENT:
......@@ -170,6 +172,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
default:
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
}
obidebug(1, "\nCan't open OBIDMS directory");
free(directory_name);
return NULL;
}
......@@ -179,6 +182,7 @@ OBIDMS_p obi_open_dms(const char* dms_name)
if (dms == NULL)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nError allocating the memory for the OBIDMS structure");
free(directory_name);
return NULL;
}
......@@ -207,6 +211,7 @@ OBIDMS_p obi_dms(const char* dms_name)
return obi_open_dms(dms_name);
};
obidebug(1, "\nError checking if an OBIDMS directory exists");
return NULL;
}
......@@ -223,6 +228,11 @@ int obi_list_columns(OBIDMS_p dms)
d = dms->directory;
dir = readdir(d);
if (dir == NULL)
{
obidebug(1, "\nError reading in the OBIDMS directory");
return -1;
}
fprintf(stderr, "Column name\tData type\tLatest version");
......@@ -250,7 +260,7 @@ int obi_list_columns(OBIDMS_p dms)
rewinddir(d);
return(0);
return 0;
}
......@@ -261,6 +271,7 @@ int obi_close_dms(OBIDMS_p dms)
if (closedir(dms->directory) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
obidebug(1, "\nError closing an OBIDSM directory");
free(dms);
return -1;
}
......
......@@ -22,6 +22,10 @@
#include "obidms.h"
#include "private_at_functions.h"
#include "obierrno.h"
#include "obidebug.h"
#define DEBUG_LEVEL 0
/**************************************************************************
......@@ -69,6 +73,7 @@ static char* build_column_directory_name(const char* column_name)
if (asprintf(&column_directory_name, "%s.obicol", column_name) < 0)
{
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
obidebug(1, "\nError building a column directory name");
return NULL;
}
......@@ -76,6 +81,7 @@ static char* build_column_directory_name(const char* column_name)
if (strlen(column_directory_name) >= OBIDMS_COLUMN_DIR_MAX_NAME)
{
obi_set_errno(OBICOLDIR_LONG_NAME_ERROR);
obidebug(1, "\nError building a column directory name");
free(column_directory_name);
return NULL;
}
......@@ -101,16 +107,14 @@ int obi_column_directory_exists(OBIDMS_p dms, const char* column_name)
// 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);
obidebug(1, "\nError getting a file descriptor for an OBIDMS directory");
free(column_directory_name);
return -1;
}
......@@ -120,6 +124,7 @@ int obi_column_directory_exists(OBIDMS_p dms, const char* column_name)
if (full_path == NULL)
{
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
obidebug(1, "\nError getting path for an OBIDMS directory");
free(column_directory_name);
return -1;
}
......@@ -154,6 +159,7 @@ OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char*
if (dms_file_descriptor < 0)
{
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
obidebug(1, "\nError getting a file descriptor for an OBIDMS directory");
free(column_directory_name);
return NULL;
}
......@@ -165,8 +171,8 @@ OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char*
obi_set_errno(OBICOLDIR_EXIST_ERROR);
else
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
obidebug(1, "\nError creating a column directory");
free(column_directory_name);
close(dms_file_descriptor);
return NULL;
}
......@@ -179,9 +185,9 @@ OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char*
OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* column_name)
{
OBIDMS_column_directory_p column_directory;
char* column_directory_name;
DIR* directory;
int dms_file_descriptor;
char* column_directory_name;
DIR* directory;
int dms_file_descriptor;
column_directory = NULL;
......@@ -195,6 +201,7 @@ OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* co
if (dms_file_descriptor < 0)
{
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
obidebug(1, "\nError getting a file descriptor for an OBIDMS directory");
free(column_directory_name);
return NULL;
}
......@@ -219,8 +226,8 @@ OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* co
default:
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
}
obidebug(1, "\nError opening a column directory");
free(column_directory_name);
close(dms_file_descriptor);
return NULL;
}
......@@ -229,8 +236,8 @@ OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* co
if (column_directory == NULL)
{
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
obidebug(1, "\nError allocating the memory for an OBIDMS column directory structure");
free(column_directory_name);
close(dms_file_descriptor);
return NULL;
}
......@@ -258,6 +265,7 @@ OBIDMS_column_directory_p obi_column_directory(OBIDMS_p dms, const char* column_
return obi_open_column_directory(dms, column_name);
};
obidebug(1, "\nError checking if a column directory exists");
return NULL;
}
......@@ -270,6 +278,7 @@ int obi_close_column_directory(OBIDMS_column_directory_p column_directory)
if (closedir(column_directory->directory) < 0)
{
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
obidebug(1, "\nError closing a column directory");
free(column_directory);
return -1;
}
......
......@@ -19,6 +19,11 @@
#include <dirent.h>
#include "private_at_functions.h"
#include "obidebug.h"
#include "obierrno.h"
#define DEBUG_LEVEL 0
/**********************************************************************
......@@ -34,12 +39,18 @@ char* get_full_path(int directory_file_descriptor, const char* path_name)
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
if (full_path == NULL)
{
obidebug(1, "\nError allocating memory for the char* path to a file or directory");
return NULL;
}
if (fcntl(directory_file_descriptor, F_GETPATH, full_path) < 0)
{
obidebug(1, "\nError getting the path to a file or directory");
return NULL;
}
// check errors TODO
// TODO check errors
strlcat(full_path, "/", MAX_PATH_LEN);
strlcat(full_path, path_name, MAX_PATH_LEN);
......@@ -57,6 +68,8 @@ DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
return NULL;
directory = opendir(full_path);
if (directory == NULL)
obidebug(1, "\nError opening a directory");
free(full_path);
......
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