X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=adu.c;h=9fb70bed1446f41d4a6049db036e28c5bf6d971e;hp=cd77fd9f9f4741b7c9f805072737bc4216f1f36e;hb=f6b8d4e6ca179d4431d3dc3a851850f8dbecf079;hpb=7c5fafb3a13d58cdfc96f90b74972f7d9f7adef1 diff --git a/adu.c b/adu.c index cd77fd9..9fb70be 100644 --- a/adu.c +++ b/adu.c @@ -5,6 +5,16 @@ */ /** \file adu.c \brief The main functions used by all modes of operation. */ + +/** + * \mainpage adu API reference + * + * - Modes of operation: \ref select.c, \ref create.c, \ref interactive.c + * - User handling: \ref user.c + * - Error handling: \ref error.h + * - Library-type functions: \ref fd.c, \ref format.c, \ref string.c, \ref portable_io.h + */ + #include "adu.h" #include /* readdir() */ #include @@ -17,10 +27,11 @@ #include "string.h" #include "error.h" +/** Define the array of error descriptions. */ DEFINE_ERRLIST; /** - * The error code of the last osl library function. + * The error code of the last called osl library function. * * \sa osl(). */ @@ -35,6 +46,8 @@ struct gengetopt_args_info conf; /** Options passed to --select-options. */ struct select_args_info select_conf; +/** Computed database dir */ +char *database_dir; /** * The table containing the directory names and statistics. @@ -172,21 +185,27 @@ static int init_signals(void) */ int open_dir_table(int create) { + int ret; if (dir_table) return 1; - dir_table_desc.dir = adu_strdup(conf.database_dir_arg); + dir_table_desc.dir = adu_strdup(database_dir); if (create) { + INFO_LOG("creating database directory structure\n"); + ret = mkpath(dir_table_desc.dir, 0777); + if (ret < 0) + goto out; NOTICE_LOG("creating dir table\n"); - int ret = osl(osl_create_table(&dir_table_desc)); - if (ret < 0) { - free((char *)dir_table_desc.dir); - return ret; - } + ret = osl(osl_create_table(&dir_table_desc)); + if (ret < 0) + goto out; } INFO_LOG("opening dir table\n"); return osl(osl_open_table(&dir_table_desc, &dir_table)); +out: + free((char *)dir_table_desc.dir); + return ret; } static int check_args(void) @@ -210,7 +229,7 @@ static int check_args(void) return 1; } -static int print_complete_help_and_die(void) +static void print_complete_help_and_die(void) { const char **line; @@ -282,6 +301,11 @@ int main(int argc, char **argv) if (ret < 0) goto out; ret = -E_SYNTAX; + if (conf.database_dir_given) + database_dir = adu_strdup(conf.database_dir_arg); + else + database_dir = make_message("%s%s", + conf.database_root_arg, conf.base_dir_arg); if (conf.select_given) ret = com_select(); else if (conf.create_given) @@ -296,6 +320,7 @@ out: ERROR_LOG("%s\n", adu_strerror(-ret)); return -EXIT_FAILURE; } + free(database_dir); cmdline_parser_free(&conf); select_cmdline_parser_free(&select_conf); return EXIT_SUCCESS;