Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : #if 0
4 : : #include <locale.h>
5 : : #endif
6 : :
7 : : /**
8 : : *
9 : : * Initialize the Config structure that stores runtime settings.
10 : : * Start with zeroed memory and then apply explicit defaults.
11 : : *
12 : : */
13 : 455 : void init_config(void)
14 : : {
15 : : /* This function was reviewed line by line by a human and is not AI-generated
16 : : Any change to this function requires separate explicit approval */
17 : :
18 : : // Fill out with zeroes
19 : 455 : memset(config,0,sizeof(Config));
20 : :
21 : : // Application start time for total runtime reporting.
22 : 455 : config->app_start_time_ns = cur_time_monotonic_ns();
23 : :
24 : : // Max available size of a path
25 : 455 : config->running_dir_size = 0;
26 : :
27 : : // Absolute path name of the working directory
28 : : // A directory where the program was executed
29 : 455 : config->running_dir = NULL;
30 : :
31 : : // Show progress bar
32 : 455 : config->progress = false;
33 : :
34 : : // Print remembered warnings and errors before exit
35 : 455 : config->show_remembered_messages_at_exit = false;
36 : :
37 : : // Force update of the database
38 : 455 : config->force = false;
39 : :
40 : : // Additional output for debugging
41 : 455 : config->verbose = false;
42 : :
43 : : // Force update of the database with new,
44 : : // changed or deleted files. This is special
45 : : // protection against accidental deletion of
46 : : // information from the database.
47 : 455 : config->update = false;
48 : :
49 : : // Parameter to compare database
50 : 455 : config->compare = false;
51 : :
52 : : // Show all compare output categories by default
53 : 455 : config->compare_filter = CF_NONE_SPECIFIED;
54 : :
55 : : // An array of paths to traverse
56 : 455 : config->paths = NULL;
57 : :
58 : : // The pointer to the primary database
59 : 455 : config->db = NULL;
60 : :
61 : : /// The flags parameter to sqlite3_open_v2()
62 : : /// must include, at a minimum, one of the
63 : : /// following flag combinations:
64 : : /// - SQLITE_OPEN_READONLY
65 : : /// - SQLITE_OPEN_READWRITE
66 : : /// - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
67 : : /// Default value: RO
68 : 455 : config->sqlite_open_flag = SQLITE_OPEN_READONLY;
69 : :
70 : : // The path of DB file
71 : : // Set element size for libmem string descriptors; other fields are already zeroed by memset
72 : 455 : config->db_primary_file_path.element_size = sizeof(char);
73 : :
74 : : // Set true only when the primary database path is ":memory:"
75 : 455 : config->db_primary_path_is_memory = false;
76 : :
77 : : // The name of DB file
78 : : // Set element size for libmem string descriptors; other fields are already zeroed by memset
79 : 455 : config->db_file_name.element_size = sizeof(char);
80 : :
81 : : // Pointers to the array with database paths
82 : 455 : config->db_file_paths = NULL;
83 : :
84 : : // Pointers to the array with database file names
85 : 455 : config->db_file_names = NULL;
86 : :
87 : : /// Allow or disallow database table
88 : : /// initialization. True by default
89 : 455 : config->db_initialize_tables = true;
90 : :
91 : : /// Flag indicating whether the primary database file exists
92 : 455 : config->db_primary_file_exists = false;
93 : :
94 : : // The flag means that the DB already exists
95 : : // and not empty
96 : 455 : config->db_contains_data = false;
97 : :
98 : : // Must be specified additionally in order
99 : : // to remove from the database mention of
100 : : // files that matches the regular expression
101 : : // passed through the ignore option(s)
102 : : // This is special protection against accidental
103 : : // deletion of information from the database.
104 : 455 : config->db_drop_ignored = false;
105 : :
106 : : // Allow dropping database records for inaccessible files
107 : : // (permission denied). Disabled by default.
108 : 455 : config->db_drop_inaccessible = false;
109 : :
110 : : /// Select database validation level: 'quick' for basic
111 : : /// structure check, 'full' (default) for comprehensive
112 : : /// integrity verification
113 : 455 : config->db_check_level = FULL;
114 : :
115 : : // Flag that reflects the presence of any changes
116 : : // since the last research
117 : 455 : config->db_primary_file_modified = false;
118 : :
119 : : // Recursion depth limit. The depth of the traversal,
120 : : // numbered from 0 to N, where a file could be found.
121 : : // Representing the maximum of the starting
122 : : // point (from root) of the traversal.
123 : : // The root itself is numbered 0
124 : 455 : config->maxdepth = -1;
125 : :
126 : : // Ignore those relative paths
127 : : // The string array of PCRE2 regular expressions
128 : 455 : config->ignore = NULL;
129 : :
130 : : // Suppress per-file log output for paths matched by --ignore
131 : 455 : config->quiet_ignored = false;
132 : :
133 : : // Include those relative paths even if
134 : : // they were excluded via the --ignore option
135 : : // The string array of PCRE2 regular expressions
136 : 455 : config->include = NULL;
137 : 455 : config->include_specified = false;
138 : :
139 : : // Relative paths whose checksums must never be recalculated
140 : : // after the initial write. PCRE2 regular expressions.
141 : 455 : config->lock_checksum = NULL;
142 : :
143 : : // Force a full rehash for checksum-locked entries
144 : 455 : config->rehash_locked = false;
145 : :
146 : : // Perform a trial run with no changes made
147 : 455 : config->dry_run = false;
148 : :
149 : : // Allow hashing in dry-run mode (--dry-run=with-checksums)
150 : 455 : config->dry_run_with_checksums = false;
151 : :
152 : : // Define the comparison string
153 : 455 : const char *compare_string = "true";
154 : :
155 : : // Retrieve the value of the "TESTING" environment variable,
156 : : // Validate if the environment variable TESTING exists
157 : : // and if it match to "true" display ONLY testing
158 : : // messages for System Testing purposes.
159 : 455 : const char *env_var = getenv("TESTING");
160 : :
161 : : // Check if it exists and compare it to "true"
162 [ + - + + ]: 455 : if(env_var != NULL && strcasecmp(env_var,compare_string) == 0)
163 : : {
164 : : // Global variable
165 : 343 : rational_logger_mode = TESTING;
166 : : } else {
167 : : // Global variable, default value
168 : 112 : rational_logger_mode = REGULAR;
169 : : }
170 : :
171 : : /// This option prevents directory traversal from descending into
172 : : /// directories that have a different device number than the file
173 : : /// from which the descent began
174 : 455 : config->start_device_only = false;
175 : :
176 : : // Pre-compiled PCRE2 patterns for --ignore, populated by compile_patterns() only if --ignore was specified
177 : 455 : config->ignore_pcre_compiled = NULL;
178 : :
179 : : // Pre-compiled PCRE2 patterns for --include, populated by compile_patterns() only if --include was specified
180 : 455 : config->include_pcre_compiled = NULL;
181 : :
182 : : // Pre-compiled PCRE2 patterns for --lock-checksum, populated by compile_patterns() only if --lock-checksum was specified
183 : 455 : config->lock_checksum_pcre_compiled = NULL;
184 : :
185 : : /// Track both file metadata (created/modified dates) and size changes
186 : : /// for change detection. Out of the box, only size changes trigger
187 : : /// a rescan. When enabled, any update to timestamps or file size
188 : : /// will force a rescan and update the checksum in the database.
189 : 455 : config->watch_timestamps = false;
190 : :
191 : : #if 0
192 : : if(NULL != setlocale(LC_ALL,""))
193 : : {
194 : : slog(TRACE,"Enable locale support\n");
195 : : } else {
196 : : slog(TRACE,"Failed to set locale\n");
197 : : }
198 : : #endif
199 : :
200 : 455 : slog(TRACE,"Configuration initialization is finished\n");
201 : 455 : }
|