LCOV - code coverage report
Current view: top level - src - db_check_changes.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 66.7 % 24 16
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "precizer.h"
       2              : 
       3           68 : Return db_check_changes(void)
       4              : {
       5              :         /** @var Return status
       6              :          *  @brief The status that will be passed to return() before exiting
       7              :          *  @details By default, the function worked without errors
       8              :          */
       9           68 :         Return status = SUCCESS;
      10              : 
      11           68 :         struct stat db_current_stat = {0};
      12              : 
      13           68 :         int rc = stat(config->db_primary_file_path,&db_current_stat);
      14              : 
      15           68 :         if(rc < 0)
      16              :         {
      17            0 :                 report("Stat of %s failed with error code: %d",config->db_primary_file_path,rc);
      18            0 :                 status = FAILURE;
      19              :         }
      20              : 
      21           68 :         CmpctStat before = {0};
      22           68 :         CmpctStat after = {0};
      23              : 
      24           68 :         stat_copy(&config->db_file_stat,&before);
      25           68 :         stat_copy(&db_current_stat,&after);
      26              : 
      27           68 :         Changed changes = compare_file_metadata_equivalence(&before,&after);
      28              : 
      29           68 :         if(IDENTICAL != changes)
      30              :         {
      31           40 :                 if(config->db_primary_file_modified == true)
      32              :                 {
      33           40 :                         slog(EVERY,BOLD "The database file %s has been modified since the program was launched" RESET "\n",config->db_file_name);
      34              :                 } else {
      35            0 :                         slog(ERROR,"Internal error: The database file %s has changed, but according to the global variable tracking modification status, this should not have happened!\n",config->db_file_name);
      36              : 
      37            0 :                         if(!(rational_logger_mode & SILENT))
      38              :                         {
      39            0 :                                 show_difference(changes,&before,&after);
      40              :                         }
      41            0 :                         status = WARNING;
      42              :                 }
      43              :         } else {
      44           28 :                 if(config->db_primary_file_modified == true)
      45              :                 {
      46            0 :                         slog(ERROR,"Internal error. The database file %s has NOT changed, but according to the state of the global variable tracking modifications, it should have!\n",config->db_file_name);
      47            0 :                         status = WARNING;
      48              :                 } else {
      49           28 :                         slog(EVERY,BOLD "The database file %s has NOT been modified since the program was launched" RESET "\n",config->db_file_name);
      50              :                 }
      51              :         }
      52              : 
      53           68 :         provide(status);
      54              : }
        

Generated by: LCOV version 2.0-1