aboutsummaryrefslogtreecommitdiff
path: root/src/duplicate_finder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/duplicate_finder.c')
-rw-r--r--src/duplicate_finder.c66
1 files changed, 56 insertions, 10 deletions
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;
+}
+