LCOV - code coverage report
Current view: top level - src - directory_access.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.3 % 13 12
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 1 1
Branches: 60.0 % 10 6

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Check directory accessibility and skip its subtree when needed
       5                 :             :  *
       6                 :             :  * Checks @p relative_path from the already opened traversal root. If the
       7                 :             :  * directory is unavailable, the same relative path is shown to the user and
       8                 :             :  * remembered for the final warning summary
       9                 :             :  *
      10                 :             :  * @param[in] file_systems FTS traversal handle
      11                 :             :  * @param[in] entry Current FTS directory entry
      12                 :             :  * @param[in] root_directory_fd Open descriptor for the traversal root
      13                 :             :  * @param[in] relative_path Path to the directory relative to the traversal root
      14                 :             :  * @param[in,out] first_iteration Banner sentinel for the first visible output line
      15                 :             :  * @param[in,out] summary Traversal state used by slog_show()
      16                 :             :  * @return SUCCESS when the directory access state was handled cleanly
      17                 :             :  */
      18                 :       14778 : Return directory_access_verify(
      19                 :             :         FTS              *file_systems,
      20                 :             :         FTSENT           *entry,
      21                 :             :         const int        root_directory_fd,
      22                 :             :         const memory     *relative_path,
      23                 :             :         bool             *first_iteration,
      24                 :             :         TraversalSummary *summary)
      25                 :             : {
      26                 :             :         /* Status returned by this function through provide()
      27                 :             :            Default value assumes successful completion */
      28                 :       14778 :         Return status = SUCCESS;
      29                 :             : 
      30         [ -  + ]:       14778 :         if(relative_path == NULL)
      31                 :             :         {
      32                 :           0 :                 provide(status);
      33                 :             :         }
      34                 :             : 
      35                 :             :         /* Directory traversal needs both read permission and execute permission.
      36                 :             :            Read permission lets the program list entries inside the directory, while
      37                 :             :            execute permission lets it enter the directory and reach child paths */
      38                 :       14778 :         FileAccessStatus access_status = file_check_access(root_directory_fd,relative_path,R_OK | X_OK);
      39                 :             : 
      40                 :             :         /* When a directory cannot be read or has disappeared during traversal, show
      41                 :             :            the user its relative path and remember the warning for the final summary.
      42                 :             :            If no --include rules were supplied, the whole subtree can be skipped
      43                 :             :            because there is no later include pattern that could make a child visible */
      44         [ +  + ]:       14778 :         if(access_status == FILE_ACCESS_DENIED
      45         [ +  - ]:       14774 :                 || access_status == FILE_NOT_FOUND
      46         [ -  + ]:       14774 :                 || access_status == FILE_ACCESS_ERROR)
      47                 :             :         {
      48                 :           4 :                 const char *runtime_relative_path = m_text(relative_path);
      49                 :             : 
      50                 :           4 :                 slog_show(EVERY|UNDECOR|REMEMBER,false,first_iteration,summary,"inaccessible directory %s\n",runtime_relative_path);
      51                 :             : 
      52         [ +  - ]:           4 :                 if(config->include_specified == false)
      53                 :             :                 {
      54                 :           4 :                         (void)fts_set(file_systems,entry,FTS_SKIP);
      55                 :             :                 }
      56                 :             :         }
      57                 :             : 
      58                 :       14778 :         provide(status);
      59                 :             : }
        

Generated by: LCOV version 2.0-1