Line data Source code
1 : /**
2 : *
3 : * @file precizer.c
4 : * @brief Main file
5 : *
6 : */
7 : #include "precizer.h"
8 :
9 : /**
10 : * Global definitions
11 : *
12 : */
13 :
14 : // Global variable controls signals to interrupt execution
15 : // Atomic variable is very fast and will be called very often
16 : _Atomic bool global_interrupt_flag = false;
17 :
18 : // The global structure Config where all runtime settings will be stored
19 : Config _config;
20 : Config *config = &_config;
21 :
22 : /**
23 : * @mainpage
24 : * @brief precizer is a CLI application designed to verify the integrity of files after synchronization.
25 : * The program recursively traverses directories and creates a database
26 : * of files and their checksums, followed by a quick comparison.
27 : *
28 : * @author Dennis Razumovsky
29 : * @details precizer specializes in managing vast file systems.
30 : * The program identifies synchronization errors by cross-referencing
31 : * data and checksums from various sources. Alternatively, it can be
32 : * used to crawl historical changes by comparing databases from the
33 : * same sources over different times
34 : */
35 : #ifndef TESTITALL // Unit testing library
36 102 : int main(
37 : int argc,
38 : char **argv)
39 : #else
40 102 : int test_main(
41 : int argc,
42 : char **argv)
43 : #endif // TESTITALL
44 : {
45 : /// The status that will be passed to return() before exiting.
46 : /// By default, the function worked without errors.
47 204 : Return status = SUCCESS;
48 :
49 : // Initialize configuration with values
50 204 : init_config();
51 :
52 : // Fill Config structure
53 : // parsing command line arguments
54 204 : run(parse_arguments(argc,argv));
55 :
56 : // Verify that the provided paths exist and
57 : // are directories
58 203 : run(detect_paths());
59 :
60 : // Initialize signals interception like Ctrl+C
61 203 : run(init_signals());
62 :
63 : // The current directory where app being executed
64 203 : run(determine_running_dir());
65 :
66 : // Generate DB file name if
67 : // not passed as an argument
68 203 : run(db_determine_name());
69 :
70 : // Validate database file existence and set up existence flag
71 203 : run(db_primary_file_validate_existence());
72 :
73 : // Define the database operation mode
74 203 : run(db_determine_mode());
75 :
76 : // Primary database file integrity check
77 203 : run(db_primary_file_test());
78 :
79 : // Initialize SQLite database
80 203 : run(db_init());
81 :
82 : // Compare databases
83 203 : run(db_compare());
84 :
85 : // Check whether the database already exists or not yet
86 203 : run(db_contains_data());
87 :
88 : // Verify that the provided path arguments match
89 : // the paths stored in the database
90 203 : run(db_validate_paths());
91 :
92 : // Save new prefixes that has been passed as
93 : // arguments
94 203 : run(db_save_prefixes());
95 :
96 : // Just get a statistic
97 203 : run(file_list(true));
98 :
99 : // Get file list and their CRC
100 203 : run(file_list(false));
101 :
102 : // Update the database. Remove files that
103 : // no longer exist.
104 203 : run(db_delete_missing_metadata());
105 :
106 : // Disable journaling, flush the journal to the main database,
107 : // clear the cache, and close the database
108 203 : call(db_close(config->db,&config->db_primary_file_modified));
109 :
110 : // Optimizing the space occupied by a database file.
111 203 : run(db_primary_consider_vacuum());
112 :
113 : // Print out whether there have been changes to
114 : // the file system and accordingly against the database
115 : // since the last research
116 203 : run(status_of_changes());
117 :
118 : // Free allocated memory
119 : // for arrays and variables
120 203 : free_config();
121 :
122 203 : return(exit_status(status,argv));
123 : }
|