From eb50073ce5fe7bc7cb3749fd7674096ce767d095 Mon Sep 17 00:00:00 2001 From: Thorsten Töpper Date: Sun, 22 Feb 2026 23:36:17 +0100 Subject: Dump the db content in form of a ; CSV --- src/duplicate_finder.c | 66 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 10 deletions(-) (limited to 'src/duplicate_finder.c') diff --git a/src/duplicate_finder.c b/src/duplicate_finder.c index 714fd96..dae7832 100644 --- a/src/duplicate_finder.c +++ b/src/duplicate_finder.c @@ -28,22 +28,47 @@ /*=========== GLOBAL VARIABLES ===========*/ /*=========== FUNCTIONS ===========*/ +int analyze_db_content(); +int scan (const char *path); -int main(int argc, char **argv) { - int path_index = 1; +/** + * The wrapper around automated DB content analysis. + * + * @return EXIT_SUCCESS on success + * EXIT_FAILURE on failure + */ +int analyze_db_content() { - if (argc > 1) { - path_index = parse_arguments(argc, argv); + if ( ! dbi_open(option_sqlite_db_name) ) { + return EXIT_FAILURE; } - /* TODO: name as option */ - if ( ! kv_open_storage("/tmp/duplicate_finder.gdbm") ) { + + /* TODO: Implementation of several SQL queries... not in the mood */ + dbi_print_fileinfo_resolved(stdout); + + dbi_close(); + return EXIT_SUCCESS; +} + + +/** + * Scan the given path... + * + * @return EXIT_SUCCESS on success + * EXIT_FAILURE on failure + */ + +int scan(const char *path) { + if ( ! kv_open_storage(option_gdbm_db_name) ) { return EXIT_FAILURE; } - /* TODO: name as option */ - dbi_open("/tmp/duplicate_finder.sqlite"); - traverse_directory_tree((path_index == argc) ? argv[path_index] : "."); + if ( ! dbi_open(option_sqlite_db_name) ) { + return EXIT_FAILURE; + } + + traverse_directory_tree(path); #ifdef DEBUGBUILD kv_dump(stdout); @@ -58,7 +83,28 @@ int main(int argc, char **argv) { /* TODO: Implement signal handlers and add the close for sqlite and gdbm dbs there */ kv_close_storage(); dbi_close(); - return EXIT_SUCCESS; } +int main(int argc, char **argv) { + int path_index = 1; + + if (argc > 1) { + path_index = parse_arguments(argc, argv); + } else { + LOGERR("ERROR: Too few arguments given, see --help or man.\n"); + return EXIT_FAILURE; + } + + if (option_mode == MODE_SCAN) { + return scan((path_index == argc) ? argv[path_index] : "."); + } + + if (option_mode == MODE_ANALYZE_DB) { + return analyze_db_content(); + } + + LOGERR("ERROR: No proper modus operandi, the dev missed something.\n"); + return EXIT_FAILURE; +} + -- cgit v1.3