LCOV - code coverage report
Current view: top level - src - init_config.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 46 46
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 1 1
Branches: 75.0 % 4 3

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

Generated by: LCOV version 2.0-1