LCOV - code coverage report
Current view: top level - src - paths_detect.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.5 % 17 13
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 1 1
Branches: 75.0 % 12 9

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Validate the traversal roots supplied for normal scanning mode
       5                 :             :  *
       6                 :             :  * The function is skipped in `--compare` mode because compare arguments are
       7                 :             :  * database files, not directories to traverse. In normal mode it requires at
       8                 :             :  * least one root path and checks every root as an existing directory before
       9                 :             :  * traversal begins
      10                 :             :  *
      11                 :             :  * For example, `precizer tests/fixtures/diffs` stores that positional argument
      12                 :             :  * in `config->roots`; this function verifies that the directory is available
      13                 :             :  * before later code starts reading files from it
      14                 :             :  *
      15                 :             :  * @return `SUCCESS` when compare mode is active or all roots are available.
      16                 :             :  *         `FAILURE` when no root was provided or at least one root is not an
      17                 :             :  *         accessible directory
      18                 :             :  */
      19                 :         498 : Return paths_detect(void)
      20                 :             : {
      21                 :             :         /* Status returned by this function through provide()
      22                 :             :            Default value assumes successful completion */
      23                 :         498 :         Return status = SUCCESS;
      24                 :             : 
      25                 :             :         // Don't do anything
      26         [ +  + ]:         498 :         if(config->compare == true)
      27                 :             :         {
      28                 :             :                 // The option to compare databases has been selected.
      29                 :             :                 // There is no need to compare paths
      30                 :         118 :                 slog(TRACE,"Comparing databases. Directory path verification is not required\n");
      31                 :         118 :                 provide(status);
      32                 :             : 
      33                 :             :         } else {
      34                 :             :                 // Check directory paths passed as arguments, traverse
      35                 :             :                 // them for files, and store the file metadata in the database
      36                 :         380 :                 slog(TRACE,"Checking directory paths provided as arguments\n");
      37                 :             :         }
      38                 :             : 
      39                 :             :         // Check traversal roots supplied as positional arguments
      40         [ -  + ]:         380 :         if(config->roots.length == 0)
      41                 :             :         {
      42                 :           0 :                 slog(ERROR,"The PATH is not defined\n");
      43                 :           0 :                 status = FAILURE;
      44                 :             :         }
      45                 :             : 
      46         [ +  - ]:         380 :         if(SUCCESS == status)
      47                 :             :         {
      48   [ +  +  +  + ]:        1142 :                 m_string_array_foreach(conf(roots),root)
      49                 :             :                 {
      50                 :         382 :                         const char *root_path = m_text(root);
      51                 :             : 
      52         [ -  + ]:         382 :                         if(NOT_FOUND == file_availability(root_path,NULL,SHOULD_BE_A_DIRECTORY))
      53                 :             :                         {
      54                 :           0 :                                 status = FAILURE;
      55                 :           0 :                                 break;
      56                 :             :                         }
      57                 :             :                 }
      58                 :             :         }
      59                 :             : 
      60                 :         380 :         slog(TRACE,"Path detection is finished\n");
      61                 :             : 
      62                 :         380 :         provide(status);
      63                 :             : }
        

Generated by: LCOV version 2.0-1