aboutsummaryrefslogtreecommitdiff
path: root/src/duplicate_finder.c
blob: 714fd962bddec373f960bf00bc1badc11603df3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* SPDX-License-Identifier: Apache-2.0 */

/**
 * Copyright 2026 Thorsten Töpper
 *
 * Keep track of files across different paths or filesystems with a sqlite db
 * and identify duplicates. This utility should be used for housekeeping when
 * spreading data across multiple FS / integrate old disks into newer setups.
 *
 * The DB stores SHA512 and SHA256 hashes calculated with the OpenSSL library,
 * path and filenames and their corresponding stat() FS data.
 *
 * @file duplicate_finder.c
 *
 * vim:ts=4:sw=4:expandtab
 */

#include <stdlib.h>

#include "trace_macros.h"
#include "options.h"
#include "kv_manager.h"
#include "directory_scanner.h"
#include "database_interaction.h"

/*=========== DEFINES, CONSTANTS AND TYPES ===========*/

/*=========== GLOBAL VARIABLES ===========*/

/*=========== FUNCTIONS ===========*/

int main(int argc, char **argv) {
    int path_index = 1;

    if (argc > 1) {
        path_index = parse_arguments(argc, argv);
    }

    /* TODO: name as option */
    if ( ! kv_open_storage("/tmp/duplicate_finder.gdbm") ) {
        return EXIT_FAILURE;
    }

    /* TODO: name as option */
    dbi_open("/tmp/duplicate_finder.sqlite");
    traverse_directory_tree((path_index == argc) ? argv[path_index] : ".");

#ifdef DEBUGBUILD
    kv_dump(stdout);
#endif

    process_gdbm_content();

#ifdef DEBUGBUILD
    kv_dump(stdout);
#endif

    /* TODO: Implement signal handlers and add the close for sqlite and gdbm dbs there */
    kv_close_storage();
    dbi_close();

    return EXIT_SUCCESS;
}