LCOV - code coverage report
Current view: top level - src - show_relative_path.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.0 % 100 85
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 3 3

            Line data    Source code
       1              : #include "precizer.h"
       2              : 
       3              : /**
       4              :  * @brief Retrieve a const pointer to a flag descriptor by index.
       5              :  *
       6              :  * Uses the mem helper to obtain a typed readonly view of the Flags array and
       7              :  * performs bounds checking. Returns NULL if the descriptor is missing, type
       8              :  * verification fails, or the index is out of range.
       9              :  */
      10          198 : static const Flags *lookup(
      11              :         const memory *flags,
      12              :         size_t       index)
      13              : {
      14          198 :         const Flags *flags_data = cdata(Flags,flags);
      15              : 
      16          198 :         if(flags_data == NULL || index >= flags->length)
      17              :         {
      18            0 :                 return(NULL);
      19              :         }
      20              : 
      21          198 :         return(&flags_data[index]);
      22              : }
      23              : 
      24              : /**
      25              :  * @brief Prints combinations of change flags for a file.
      26              :  *
      27              :  * This function evaluates a bitmask of change flags and prints the corresponding descriptions
      28              :  * (e.g., "size", "ctime", "mtime") along with their metadata differences. It also indicates
      29              :  * whether the file will be rehashed.
      30              :  *
      31              :  */
      32          156 : static void print_changes(
      33              :         Changed         change_flags_mask,
      34              :         const DBrow     *dbrow,
      35              :         const CmpctStat *stat)
      36              : {
      37          156 :         if(!((rational_logger_mode & VERBOSE) || config->watch_timestamps == true))
      38              :         {
      39           90 :                 return;
      40              :         }
      41              : 
      42           66 :         create(Flags,flags);
      43              : 
      44           66 :         resize(flags,3);
      45              : 
      46           66 :         Flags *flags_data = data(Flags,flags);
      47              : 
      48           66 :         if(flags_data == NULL)
      49              :         {
      50            0 :                 del(flags);
      51            0 :                 return;
      52              :         }
      53              : 
      54           66 :         flags_data[0] = (Flags){SIZE_CHANGED,"size"};
      55           66 :         flags_data[1] = (Flags){STATUS_CHANGED_TIME,"ctime"};
      56           66 :         flags_data[2] = (Flags){MODIFICATION_TIME_CHANGED,"mtime"};
      57              : 
      58           66 :         unsigned int flags_found = 0;
      59              : 
      60              :         /* Check each flag */
      61          264 :         for(size_t i = 0; i < flags->length; i++)
      62              :         {
      63          198 :                 const Flags *flag = lookup(flags,i);
      64              : 
      65          198 :                 if(flag == NULL)
      66              :                 {
      67            0 :                         break;
      68              :                 }
      69              : 
      70          198 :                 if(change_flags_mask & flag->flag_value)
      71              :                 {
      72              :                         /* Add separator if not the first flag */
      73          142 :                         if(flags_found > 0)
      74              :                         {
      75           76 :                                 slog(EVERY|UNDECOR," & ");
      76              :                         } else {
      77           66 :                                 slog(EVERY|UNDECOR," changed ");
      78              :                         }
      79              : 
      80          142 :                         slog(EVERY|UNDECOR,"%s",flag->flag_name);
      81              : 
      82          142 :                         show_metadata(EVERY,flag->flag_value,&dbrow->saved_stat,stat);
      83              : 
      84          142 :                         flags_found++;
      85              :                 }
      86              :         }
      87              : 
      88           66 :         del(flags);
      89              : }
      90              : 
      91              : /**
      92              :  * @brief Displays the relative path of a file with additional contextual information.
      93              :  *
      94              :  * This function prints the relative path of a file along with explanations of what actions
      95              :  * will be taken regarding the file (e.g., ignore, updated, added, or rehashed). It also handles
      96              :  * initial messages for traversal, updates, and warnings.
      97              :  *
      98              :  */
      99         1208 : void show_relative_path(
     100              :         const char      *relative_path,
     101              :         const Changed   *metadata_of_scanned_and_saved_files,
     102              :         const DBrow     *dbrow,
     103              :         const CmpctStat *stat,
     104              :         bool            *first_iteration,
     105              :         const bool      *rehashing_from_the_beginning,
     106              :         const bool      *ignore,
     107              :         const bool      *include,
     108              :         const bool      *locked_checksum_file,
     109              :         const bool      *lock_checksum_violation,
     110              :         bool            *at_least_one_file_was_shown,
     111              :         const bool      *rehash,
     112              :         const bool      *count_size_of_all_files,
     113              :         const bool      *is_readable,
     114              :         const bool      *zero_size_file)
     115              : {
     116         1208 :         bool show_traversal_started = false;
     117         1208 :         bool show_update_warning = false;
     118         1208 :         bool show_changes_will_be_reflected = false;
     119         1208 :         bool show_files_will_be_added = false;
     120              : 
     121         1208 :         if(*first_iteration == true)
     122              :         {
     123          128 :                 *first_iteration = false;
     124              : 
     125          128 :                 if(*count_size_of_all_files == false)
     126              :                 {
     127          128 :                         show_traversal_started = true;
     128              :                 }
     129              : 
     130          128 :                 if(config->db_contains_data == true)
     131              :                 {
     132           50 :                         if(config->update == true)
     133              :                         {
     134           50 :                                 show_update_warning = true;
     135           50 :                                 config->the_update_warning_has_already_been_shown = true;
     136              :                         }
     137              : 
     138           50 :                         show_changes_will_be_reflected = true;
     139              : 
     140              :                 } else {
     141              : 
     142           78 :                         show_files_will_be_added = true;
     143              :                 }
     144              :         }
     145              : 
     146         1208 :         if(show_update_warning == true)
     147              :         {
     148           50 :                 slog(EVERY,"The " BOLD "--update" RESET " option has been used, so the information about files will be updated against the database %s\n",config->db_file_name);
     149              :         }
     150              : 
     151         1208 :         if(show_traversal_started == true)
     152              :         {
     153          128 :                 slog(EVERY,"File traversal started\n");
     154              :         }
     155              : 
     156         1208 :         if(show_changes_will_be_reflected == true)
     157              :         {
     158           50 :                 slog(EVERY,BOLD "These files were added or changed on disk and will be reflected against the DB %s:" RESET "\n",config->db_file_name);
     159              :         }
     160              : 
     161         1208 :         if(show_files_will_be_added == true)
     162              :         {
     163           78 :                 slog(EVERY,BOLD "These files will be added against the %s database:" RESET "\n",config->db_file_name);
     164              :         }
     165              : 
     166              :         // Print if NOT silent
     167         1208 :         if(!(rational_logger_mode & SILENT))
     168              :         {
     169          992 :                 *at_least_one_file_was_shown = true;
     170              :         }
     171              : 
     172              :         /* Prefixes */
     173              : 
     174         1208 :         if(*is_readable == false)
     175              :         {
     176            2 :                 slog(EVERY|UNDECOR,"%s %s\n","inaccessible",relative_path);
     177              : 
     178              :         /* Add or update */
     179              : 
     180         1206 :         } else if(dbrow->relative_path_already_in_db == false){
     181              : 
     182              :                 /* Add new */
     183              : 
     184         1034 :                 if(*ignore == true)
     185              :                 {
     186            6 :                         slog(EVERY|UNDECOR,"%s %s\n","ignore & do not add",relative_path);
     187              : 
     188         1028 :                 } else if(*include == true){
     189              : 
     190            0 :                         slog(EVERY|UNDECOR,"%s %s\n","add included",relative_path);
     191              : 
     192         1028 :                 } else if(*locked_checksum_file == true){
     193              : 
     194           38 :                         slog(EVERY|UNDECOR,"%s %s\n","lock checksum",relative_path);
     195              : 
     196          990 :                 } else if(*zero_size_file == true){
     197              : 
     198            2 :                         slog(EVERY|UNDECOR,"%s %s\n","add as empty",relative_path);
     199              : 
     200              :                 } else {
     201              : 
     202          988 :                         slog(EVERY|UNDECOR,"%s %s\n","add",relative_path);
     203              :                 }
     204              : 
     205              :         } else {
     206              : 
     207              :                 /* Update existing */
     208              : 
     209          172 :                 if(*ignore == true)
     210              :                 {
     211            8 :                         slog(EVERY|UNDECOR,"ignored & do not update %s\n",relative_path);
     212              : 
     213          164 :                 } else if(*include == true){
     214              : 
     215            0 :                         slog(EVERY|UNDECOR,"update included");
     216              : 
     217            0 :                         print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     218              : 
     219            0 :                         slog(EVERY|UNDECOR," %s\n",relative_path);
     220              : 
     221          164 :                 } else if(*lock_checksum_violation == true){
     222              : 
     223            8 :                         slog(EVERY|UNDECOR,RED "checksum locked, data corruption detected" RESET);
     224              : 
     225            8 :                         print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     226              : 
     227            8 :                         slog(EVERY|UNDECOR," %s\n",relative_path);
     228              : 
     229          156 :                 } else if(*zero_size_file == true){
     230              : 
     231            0 :                         slog(EVERY|UNDECOR,"update as empty");
     232              : 
     233            0 :                         print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     234              : 
     235            0 :                         slog(EVERY|UNDECOR," %s\n",relative_path);
     236              : 
     237          156 :                 } else if(*rehash == true){
     238              : 
     239           66 :                         if(*rehashing_from_the_beginning == true)
     240              :                         {
     241            0 :                                 slog(EVERY|UNDECOR,"rehash from the beginning");
     242              : 
     243            0 :                                 print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     244              : 
     245            0 :                                 slog(EVERY|UNDECOR," %s\n",relative_path);
     246              : 
     247           66 :                         } else if(dbrow->saved_offset > 0){
     248            0 :                                 slog(EVERY|UNDECOR,"continue to rehash from %s %s\n",bkbmbgbtbpbeb((const size_t)dbrow->saved_offset),relative_path);
     249              : 
     250           66 :                         } else if(*locked_checksum_file == true){
     251              : 
     252           10 :                                 slog(EVERY|UNDECOR,"rehash locked");
     253              : 
     254           10 :                                 if(*metadata_of_scanned_and_saved_files != IDENTICAL)
     255              :                                 {
     256            2 :                                         print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     257              :                                 }
     258              : 
     259           10 :                                 slog(EVERY|UNDECOR," %s\n",relative_path);
     260              : 
     261              :                         } else {
     262              : 
     263           56 :                                 slog(EVERY|UNDECOR,"update & rehash");
     264              : 
     265           56 :                                 print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     266              : 
     267           56 :                                 slog(EVERY|UNDECOR," %s\n",relative_path);
     268              :                         }
     269              : 
     270              :                 } else {
     271           90 :                         slog(EVERY|UNDECOR,"update stat");
     272              : 
     273           90 :                         print_changes(*metadata_of_scanned_and_saved_files,dbrow,stat);
     274              : 
     275           90 :                         slog(EVERY|UNDECOR," %s\n",relative_path);
     276              :                 }
     277              :         }
     278         1208 : }
        

Generated by: LCOV version 2.0-1