Line data Source code
1 : #include "precizer.h"
2 :
3 : /**
4 : * @brief Check directory accessibility and skip its subtree if needed.
5 : *
6 : * Builds an absolute path from runtime_root and the FTS entry, calls
7 : * file_check_access and:
8 : * - on success returns SUCCESS;
9 : * - on denied/not found logs a message and sets FTS_SKIP;
10 : * - on access error returns FAILURE.
11 : *
12 : * @param file_systems FTS traversal handle.
13 : * @param entry Current FTS directory entry.
14 : * @param runtime_root Absolute traversal root without trailing slash.
15 : * @return SUCCESS or FAILURE.
16 : */
17 9320 : Return verify_directory_access(
18 : FTS *file_systems,
19 : FTSENT *entry,
20 : const char *runtime_root)
21 : {
22 9320 : if(runtime_root == NULL)
23 : {
24 1902 : return(SUCCESS);
25 : }
26 :
27 7418 : const char *relative_path = extract_relative_path(entry->fts_path,runtime_root);
28 :
29 7418 : char *absolute_path = NULL;
30 7418 : int length = asprintf(&absolute_path,"%s/%s",runtime_root,relative_path);
31 :
32 7418 : if(length == -1)
33 : {
34 0 : free(absolute_path);
35 0 : return(FAILURE);
36 : }
37 :
38 7418 : FileAccessStatus access_status = file_check_access(absolute_path,(size_t)length);
39 :
40 7418 : free(absolute_path);
41 :
42 7418 : if(access_status == FILE_ACCESS_ERROR)
43 : {
44 0 : return(FAILURE);
45 : }
46 :
47 7418 : if(access_status == FILE_ACCESS_DENIED || access_status == FILE_NOT_FOUND)
48 : {
49 2 : slog(EVERY|UNDECOR,"inaccessible %s\n",relative_path);
50 2 : (void)fts_set(file_systems,entry,FTS_SKIP);
51 : }
52 :
53 7418 : return(SUCCESS);
54 : }
|