diff options
| -rw-r--r-- | src/main.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -377,6 +377,7 @@ static void ftag_file_add_help(void) ftag_file_add_usage(); printf("Add files to the database. Non-files arguments are ignored.\n"); printf("Available options (all options must precede arguments):\n"); + printf(" -f do not search for duplicates\n"); printf(" -h print help message\n"); printf(" -i interactive, for each file, ask before adding it to the database\n"); printf("Tips:\n"); @@ -414,14 +415,18 @@ static void ftag_file_add(int argc, char **argv) exit(EXIT_FAILURE); } int interactive = 0; + int eliminate_duplicates = 1; while ((argc > 0) && (argv[0][0] == '-')) { switch (argv[0][1]) { - case 'i': - interactive = 1; + case 'f': + eliminate_duplicates = 0; break; case 'h': ftag_file_add_help(); exit(EXIT_SUCCESS); + case 'i': + interactive = 1; + break; default: ftag_file_add_usage(); exit(EXIT_FAILURE); @@ -430,6 +435,7 @@ static void ftag_file_add(int argc, char **argv) argc--; } + /* step 1: compute file sums */ uint32_t *sums = malloc(argc*sizeof(*sums)); struct stat st; @@ -451,11 +457,11 @@ static void ftag_file_add(int argc, char **argv) } } + /* step 2: retrieve sums of files already in the database */ sqlite3 *db; rc = sqlite3_open(DATABASE_PATH, &db); sqlite3_check(rc, db); - int next_id = table_next_id(db, "files"); int file_count = next_id; /* number of files already in the database */ uint32_t known_sums_array[file_count]; @@ -464,10 +470,12 @@ static void ftag_file_add(int argc, char **argv) .len = 0, .capacity = file_count }; - + if (!eliminate_duplicates) + goto step4; rc = sqlite3_exec(db, "SELECT sum FROM files;", get_sums_callback, &known_sums, NULL); sqlite3_check(rc, db); + /* step 3: eliminate duplicates with respect to file sum */ for (int i = 0; i < argc; i++) { const uint32_t original = sums[i]; @@ -496,6 +504,7 @@ static void ftag_file_add(int argc, char **argv) } /* step 4: perform addition to database */ +step4: for (int i = 0; i < argc; i++) { char *file = argv[i]; if (file == NULL) |
