Changeset 481 for trunk/src/sh_files.c
- Timestamp:
- Jul 18, 2015, 5:06:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_files.c
r465 r481 88 88 #include "sh_inotify.h" 89 89 #include "zAVLTree.h" 90 #include "sh_dbIO.h" 90 91 91 92 #undef FIL__ … … 211 212 } 212 213 214 char * sh_files_parse_input(const char * str_s, size_t * len) 215 { 216 char * p; 217 218 if (!str_s || *str_s == '\0') 219 return NULL; 220 221 *len = sl_strlen(str_s); 222 223 if ( (str_s[0] == '"' && str_s[*len-1] == '"' ) || 224 (str_s[0] == '\'' && str_s[*len-1] == '\'') ) 225 { 226 if (*len < 3) 227 return NULL; 228 --(*len); 229 p = sh_util_strdup_l(&str_s[1], *len); 230 p[*len-1] = '\0'; 231 --(*len); 232 } 233 else 234 { 235 p = sh_util_strdup_l(str_s, *len); 236 } 237 238 p = sh_files_C_dequote(p, len); 239 240 return p; 241 } 242 243 213 244 extern int flag_err_debug; 214 245 extern int flag_err_info; … … 251 282 char * name; 252 283 int class; 253 unsigned long check_ mask;284 unsigned long check_flags; 254 285 int rdepth; 255 286 short checked; … … 322 353 SL_RETURN((-1), _("sh_files_setrecursion")); 323 354 324 if (sh.flag.opts == 1)355 if (sh.flag.opts == S_TRUE) 325 356 reject = 1; 326 357 … … 380 411 tmp); 381 412 } 382 #ifndef REPLACE_OLD 383 /* this will tell that we have seen the file, and thus prevent 384 * deletion from the database, resulting in an incomplete 385 * message when the file reappears 386 */ 387 if (sh.flag.checkSum != SH_CHECK_INIT) 388 sh_hash_set_visited_true(ptr->name); 389 #else 413 390 414 if (sh.flag.checkSum != SH_CHECK_INIT) 391 415 sh_hash_set_missing(ptr->name); 392 #endif 416 393 417 if (sh.flag.reportonce == S_TRUE) 394 418 SET_SH_FFLAG_REPORTED(ptr->is_reported); … … 431 455 } 432 456 } 433 #ifndef REPLACE_OLD 434 if (sh.flag.checkSum != SH_CHECK_INIT) 435 sh_hash_set_visited_true(ptr->name); 436 #else 457 437 458 /* delete from database 438 459 */ 439 460 if (sh.flag.checkSum != SH_CHECK_INIT) 440 461 sh_hash_set_missing(ptr->name); 441 #endif442 462 } 443 463 else … … 494 514 495 515 496 if (flag_err_info == S L_TRUE)516 if (flag_err_info == S_TRUE) 497 517 { 498 518 char pstr[32]; … … 508 528 { 509 529 sh_inotify_add_watch_later(ptr->name, &sh_file_watches, NULL, 510 ptr->class, ptr->check_ mask,530 ptr->class, ptr->check_flags, 511 531 SH_INOTIFY_FILE, 0); 512 532 } … … 514 534 BREAKEXIT(sh_files_filecheck); 515 535 tmp_reported = ptr->is_reported; /* fix aliasing warning */ 516 status = sh_files_filecheck (ptr->class, ptr->check_ mask, dir, file,536 status = sh_files_filecheck (ptr->class, ptr->check_flags, dir, file, 517 537 &tmp_reported, 0); 518 538 ptr->is_reported = tmp_reported; … … 590 610 } 591 611 592 static void * sh_dummy_candidate;612 void * sh_dummy_621_candidate; 593 613 594 614 static char * intern_find_morespecific_dir(zAVLTree * tree, … … 605 625 return NULL; 606 626 607 sh_dummy_ candidate = (void *) &candidate;627 sh_dummy_621_candidate = (void *) &candidate; 608 628 609 629 SH_MUTEX_LOCK(mutex_zfiles); … … 1069 1089 1070 1090 int sh_files_push_file_int (int class, const char * str_s, size_t len, 1071 unsigned long check_ mask)1091 unsigned long check_flags) 1072 1092 { 1073 1093 dirstack_t * new_item_ptr; … … 1085 1105 new_item_ptr->name = fileName; 1086 1106 new_item_ptr->class = class; 1087 new_item_ptr->check_ mask = check_mask;1107 new_item_ptr->check_flags = check_flags; 1088 1108 new_item_ptr->rdepth = 0; 1089 1109 new_item_ptr->checked = S_FALSE; … … 1122 1142 { 1123 1143 int reported; 1124 unsigned long check_ mask= sh_files_maskof(class);1144 unsigned long check_flags = sh_files_maskof(class); 1125 1145 1126 1146 if ((sh.flag.inotify & SH_INOTIFY_INSCAN) != 0) 1127 1147 { 1128 sh_files_filecheck (class, check_ mask, str_s, NULL,1148 sh_files_filecheck (class, check_flags, str_s, NULL, 1129 1149 &reported, 0); 1130 1150 if (SH_FFLAG_REPORTED_SET(reported)) 1131 1151 sh_files_set_file_reported(str_s); 1132 1152 sh_inotify_add_watch_later(str_s, &sh_file_watches, NULL, 1133 class, check_ mask,1153 class, check_flags, 1134 1154 SH_INOTIFY_FILE, 0); 1135 1155 } 1136 1156 1137 if (MODI_AUDIT_ENABLED(check_ mask))1157 if (MODI_AUDIT_ENABLED(check_flags)) 1138 1158 { 1139 1159 sh_audit_mark(str_s); … … 1144 1164 } 1145 1165 1146 int sh_files_push_dir_int (int class, char * tail, size_t len, int rdepth, unsigned long check_ mask);1166 int sh_files_push_dir_int (int class, char * tail, size_t len, int rdepth, unsigned long check_flags); 1147 1167 1148 1168 #ifdef HAVE_GLOB_H … … 1151 1171 char * name; 1152 1172 int class; 1153 unsigned long check_ mask;1173 unsigned long check_flags; 1154 1174 int rdepth; 1155 1175 short type; … … 1160 1180 1161 1181 static int sh_files_pushglob (int class, int type, const char * p, int rdepth, 1162 unsigned long check_ mask_in, int flag)1182 unsigned long check_flags_in, int flag) 1163 1183 { 1164 1184 int globstatus = -1; … … 1167 1187 1168 1188 volatile int count = 0; 1169 volatile unsigned long check_ mask = (flag == 0) ? sh_files_maskof(class) : check_mask_in;1189 volatile unsigned long check_flags = (flag == 0) ? sh_files_maskof(class) : check_flags_in; 1170 1190 1171 1191 SL_ENTER(_("sh_files_pushglob")); … … 1190 1210 new_item_ptr->name = fileName; 1191 1211 new_item_ptr->class = class; 1192 new_item_ptr->check_ mask = check_mask;1212 new_item_ptr->check_flags = check_flags; 1193 1213 new_item_ptr->rdepth = rdepth; 1194 1214 new_item_ptr->type = type; … … 1219 1239 { 1220 1240 count += sh_files_push_file_int (class, pglob.gl_pathv[gloop], 1221 sl_strlen(pglob.gl_pathv[gloop]), check_ mask);1241 sl_strlen(pglob.gl_pathv[gloop]), check_flags); 1222 1242 } 1223 1243 else … … 1226 1246 1227 1247 count += sh_files_push_dir_int (class, pglob.gl_pathv[gloop], 1228 sl_strlen(pglob.gl_pathv[gloop]), rdepth, check_ mask);1248 sl_strlen(pglob.gl_pathv[gloop]), rdepth, check_flags); 1229 1249 } 1230 1250 } … … 1285 1305 sh_files_pushglob(testPattern->class, testPattern->type, 1286 1306 testPattern->name, testPattern->rdepth, 1287 testPattern->check_ mask, 1);1307 testPattern->check_flags, 1); 1288 1308 } 1289 1309 } … … 1306 1326 sh_files_pushglob(testPattern->class, testPattern->type, 1307 1327 testPattern->name, testPattern->rdepth, 1308 testPattern->check_ mask, 1);1328 testPattern->check_flags, 1); 1309 1329 } 1310 1330 SH_MUTEX_UNLOCK(mutex_zglob); … … 1370 1390 * is the only one -- and will stay the only one 1371 1391 */ 1372 if (sh.flag.opts == 1)1392 if (sh.flag.opts == S_TRUE) 1373 1393 { 1374 1394 sh_files_delfilestack (); … … 1378 1398 } 1379 1399 1380 if (str_s == NULL || str_s[0] == '\0') 1381 SL_RETURN((-1),_("sh_files_pushfile")); 1382 1383 len = sl_strlen(str_s); 1384 1385 if ( (str_s[0] == '"' && str_s[len-1] == '"' ) || 1386 (str_s[0] == '\'' && str_s[len-1] == '\'') ) 1387 { 1388 if (len < 3) 1389 SL_RETURN((-1),_("sh_files_pushfile")); 1390 --len; 1391 p = sh_util_strdup_l(&str_s[1], len); 1392 p[len-1] = '\0'; 1393 --len; 1394 } 1395 else 1396 { 1397 p = sh_util_strdup_l(str_s, len); 1398 } 1399 1400 p = sh_files_C_dequote(p, &len); 1400 p = sh_files_parse_input(str_s, &len); 1401 1401 if (!p || len == 0) 1402 1402 SL_RETURN((-1), _("sh_files_pushfile")); … … 1491 1491 } 1492 1492 1493 static void * sh_dummy_ptr;1493 void * sh_dummy_1493_ptr; 1494 1494 1495 1495 unsigned long sh_dirs_chk (int which) … … 1507 1507 SL_ENTER(_("sh_dirs_chk")); 1508 1508 1509 sh_dummy_ ptr = (void *) &ptr;1509 sh_dummy_1493_ptr = (void *) &ptr; 1510 1510 1511 1511 SH_MUTEX_RECURSIVE_INIT(mutex_zdirs); … … 1536 1536 BREAKEXIT(sh_files_filecheck); 1537 1537 tmp_reported = dst_ptr->is_reported; 1538 filetype = sh_files_filecheck (dst_ptr->class, dst_ptr->check_ mask,1538 filetype = sh_files_filecheck (dst_ptr->class, dst_ptr->check_flags, 1539 1539 ptr->name, 1540 1540 NULL, &tmp_reported, 0); … … 1555 1555 { 1556 1556 tmp_reported = ptr->is_reported; 1557 filetype = sh_files_filecheck (ptr->class, ptr->check_ mask,1557 filetype = sh_files_filecheck (ptr->class, ptr->check_flags, 1558 1558 ptr->name, NULL, &tmp_reported, 0); 1559 1559 ptr->is_reported = tmp_reported; … … 1562 1562 1563 1563 BREAKEXIT(sh_files_checkdir); 1564 status = sh_files_checkdir (ptr->class, ptr->check_ mask,1564 status = sh_files_checkdir (ptr->class, ptr->check_flags, 1565 1565 ptr->rdepth, ptr->name, 1566 1566 ptr->name); … … 1710 1710 } 1711 1711 1712 int sh_files_push_dir_int (int class, char * tail, size_t len, int rdepth, unsigned long check_ mask)1712 int sh_files_push_dir_int (int class, char * tail, size_t len, int rdepth, unsigned long check_flags) 1713 1713 { 1714 1714 zAVLTree * tree; … … 1726 1726 new_item_ptr->name = dirName; 1727 1727 new_item_ptr->class = class; 1728 new_item_ptr->check_ mask = check_mask;1728 new_item_ptr->check_flags = check_flags; 1729 1729 new_item_ptr->rdepth = rdepth; 1730 1730 new_item_ptr->checked = S_FALSE; … … 1776 1776 else 1777 1777 { 1778 if (MODI_AUDIT_ENABLED(check_ mask))1778 if (MODI_AUDIT_ENABLED(check_flags)) 1779 1779 { 1780 1780 sh_audit_mark(tail); … … 1794 1794 SL_ENTER(_("sh_files_pushdir")); 1795 1795 1796 if (sh.flag.opts == 1) {1796 if (sh.flag.opts == S_TRUE) { 1797 1797 sh_files_delfilestack (); 1798 1798 sh_files_deldirstack (); … … 1800 1800 } 1801 1801 1802 if (str_s == NULL || str_s[0] == '\0') 1802 p = sh_files_parse_input(str_s, &len); 1803 if (!p || len == 0) 1803 1804 SL_RETURN((-1),_("sh_files_pushdir")); 1804 1805 len = sl_strlen(str_s);1806 1807 if ( (str_s[0] == '"' && str_s[len-1] == '"' ) ||1808 (str_s[0] == '\'' && str_s[len-1] == '\'') )1809 {1810 if (len < 3)1811 SL_RETURN((-1),_("sh_files_pushdir"));1812 --len;1813 p = sh_util_strdup_l(&str_s[1], len);1814 p[len-1] = '\0';1815 --len;1816 }1817 else1818 {1819 p = sh_util_strdup_l(str_s, len);1820 }1821 1822 p = sh_files_C_dequote(p, &len);1823 if (!p || len == 0)1824 SL_RETURN((-1), _("sh_files_pushdir"));1825 1805 1826 1806 if (p[0] != '/') … … 2048 2028 * check the directory inode itself. 2049 2029 */ 2050 int sh_files_checkdir (int iclass, unsigned long check_ mask,2030 int sh_files_checkdir (int iclass, unsigned long check_flags, 2051 2031 int idepth, char * iname, 2052 2032 char * relativeName) … … 2073 2053 volatile int class_next; 2074 2054 volatile int file_class_next; 2075 volatile unsigned long check_ mask_next;2076 volatile unsigned long file_check_ mask_next;2055 volatile unsigned long check_flags_next; 2056 volatile unsigned long file_check_flags_next; 2077 2057 2078 2058 volatile int checked_flag = S_FALSE; … … 2114 2094 } 2115 2095 2116 if (flag_err_info == S L_TRUE)2096 if (flag_err_info == S_TRUE) 2117 2097 { 2118 2098 char pstr[32]; … … 2149 2129 theFile->attr_string = NULL; 2150 2130 theFile->link_path = NULL; 2151 theFile->check_ mask = check_mask;2131 theFile->check_flags = check_flags; 2152 2132 2153 2133 (void) relativeName; … … 2190 2170 { 2191 2171 sh_inotify_add_watch_later(iname, &sh_file_watches, &status, 2192 iclass, check_ mask, SH_INOTIFY_DIR, idepth);2172 iclass, check_flags, SH_INOTIFY_DIR, idepth); 2193 2173 } 2194 2174 … … 2301 2281 rdepth_next = rdepth - 1; 2302 2282 class_next = class; 2303 check_ mask_next = check_mask;2283 check_flags_next = check_flags; 2304 2284 file_class_next = class; 2305 file_check_ mask_next = check_mask;2285 file_check_flags_next = check_flags; 2306 2286 checked_flag = -1; 2307 2287 cchecked_flag = -1; … … 2322 2302 */ 2323 2303 file_class_next = dst_ptr->class; 2324 file_check_ mask_next = dst_ptr->check_mask;2304 file_check_flags_next = dst_ptr->check_flags; 2325 2305 checked_flag = dst_ptr->checked; 2326 2306 cchecked_flag = dst_ptr->childs_checked; … … 2338 2318 */ 2339 2319 file_class_next = dst_ptr->class; 2340 file_check_ mask_next = dst_ptr->check_mask;2320 file_check_flags_next = dst_ptr->check_flags; 2341 2321 checked_flag = dst_ptr->checked; 2342 2322 cchecked_flag = dst_ptr->childs_checked; … … 2355 2335 */ 2356 2336 file_class_next = dst_ptr->class; 2357 file_check_ mask_next = dst_ptr->check_mask;2337 file_check_flags_next = dst_ptr->check_flags; 2358 2338 checked_flag = dst_ptr->checked; 2359 2339 /* not set, hence always FALSE */ … … 2403 2383 */ 2404 2384 2405 checkit = sh_files_filecheck (file_class_next, file_check_ mask_next,2385 checkit = sh_files_filecheck (file_class_next, file_check_flags_next, 2406 2386 iname, 2407 2387 dirlist->sh_d_name, … … 2453 2433 rdepth_next = tmp_ptr->rdepth; 2454 2434 class_next = tmp_ptr->class; 2455 check_ mask_next = tmp_ptr->check_mask;2435 check_flags_next = tmp_ptr->check_flags; 2456 2436 /* 28. Aug 2001 reversed 2457 2437 */ … … 2471 2451 rdepth_next = tmp_ptr->rdepth; 2472 2452 class_next = tmp_ptr->class; 2473 check_ mask_next = tmp_ptr->check_mask;2453 check_flags_next = tmp_ptr->check_flags; 2474 2454 /* 28. Aug 2001 reversed 2475 2455 */ … … 2491 2471 if (cchecked_flag == S_FALSE) 2492 2472 { 2493 sh_files_checkdir (class_next, check_ mask_next, rdepth_next,2473 sh_files_checkdir (class_next, check_flags_next, rdepth_next, 2494 2474 tmpcat, dirlist->sh_d_name); 2495 2475 /* … … 2499 2479 } 2500 2480 else if (checked_flag == -1) 2501 sh_files_checkdir (class_next, check_ mask_next, rdepth_next,2481 sh_files_checkdir (class_next, check_flags_next, rdepth_next, 2502 2482 tmpcat, dirlist->sh_d_name); 2503 2483 … … 2532 2512 } while (dirlist != NULL); 2533 2513 2534 if (flag_err_info == S L_TRUE)2514 if (flag_err_info == S_TRUE) 2535 2515 { 2536 2516 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DSUM, … … 2576 2556 } 2577 2557 2558 void sh_files_fixup_mask (int class, unsigned long * check_flags) 2559 { 2560 if (class == SH_LEVEL_ALLIGNORE) 2561 MODI_SET((*check_flags), MODI_ALLIGNORE); 2562 sh_tiger_get_mask_hashtype(check_flags); 2563 return; 2564 } 2565 2578 2566 int get_the_fd (SL_TICKET ticket); 2579 2567 … … 2589 2577 static void * sh_dummy_tmpdir; 2590 2578 2591 ShFileType sh_files_filecheck (int class, unsigned long check_ mask,2579 ShFileType sh_files_filecheck (int class, unsigned long check_flags, 2592 2580 const char * dirName, 2593 2581 const char * infileName, … … 2701 2689 */ 2702 2690 sl_strlcpy (theFile->fullpath, fullpath, PATH_MAX); 2703 theFile->check_ mask = check_mask/* sh_files_maskof(class) */;2691 theFile->check_flags = check_flags /* sh_files_maskof(class) */; 2704 2692 theFile->file_reported = (*reported); 2705 2693 theFile->attr_string = NULL; … … 2712 2700 fileName, 2713 2701 theFile, fileHash, class); 2714 2702 2715 2703 if (status != 0) 2716 2704 { … … 2732 2720 /* report 2733 2721 */ 2734 if ((flag_err_debug == S L_TRUE) && (theFile->c_mode[0] == '-'))2722 if ((flag_err_debug == S_TRUE) && (theFile->c_mode[0] == '-')) 2735 2723 { 2736 2724 tmpname = sh_util_safe_name (fullpath); /* fixed in 1.5.4 */ … … 2743 2731 ++sh.statistics.files_checked; 2744 2732 2745 if ( sh.flag.checkSum == SH_CHECK_INIT /* && sh.flag.update == S_FALSE */) 2746 { 2747 sh_hash_pushdata (theFile, fileHash); 2733 if ( sh.flag.checkSum == SH_CHECK_INIT) 2734 { 2735 if (class == SH_LEVEL_ALLIGNORE) 2736 MODI_SET(theFile->check_flags, MODI_ALLIGNORE); 2737 if (S_TRUE == sh_ignore_chk_mod(theFile->fullpath)) 2738 MODI_SET(theFile->check_flags, MODI_NOCHECK); 2739 sh_tiger_get_mask_hashtype(&(theFile->check_flags)); 2740 sh_dbIO_data_write (theFile, fileHash); 2748 2741 } 2749 2742 else if (sh.flag.checkSum == SH_CHECK_CHECK … … 2752 2745 ) 2753 2746 { 2747 if (sh.flag.update == S_TRUE) 2748 { 2749 if (class == SH_LEVEL_ALLIGNORE) 2750 MODI_SET(theFile->check_flags, MODI_ALLIGNORE); 2751 if (S_TRUE == sh_ignore_chk_mod(theFile->fullpath)) 2752 MODI_SET(theFile->check_flags, MODI_NOCHECK); 2753 sh_tiger_get_mask_hashtype(&(theFile->check_flags)); 2754 } 2754 2755 sh_hash_compdata (class, theFile, fileHash, NULL, -1); 2755 2756 } … … 2760 2761 */ 2761 2762 #if !defined(O_NOATIME) 2762 if (class == SH_LEVEL_NOIGNORE && (theFile->check_ mask& MODI_ATM) != 0)2763 if (class == SH_LEVEL_NOIGNORE && (theFile->check_flags & MODI_ATM) != 0) 2763 2764 { 2764 2765 utime_buf.actime = (time_t) theFile->atime; … … 2792 2793 if (S_TRUE == sh_unix_file_exists (testpath)) 2793 2794 { 2794 sh_files_filecheck (class, check_ mask, fullpath, rsrc, &dummy, 1);2795 sh_files_filecheck (class, check_flags, fullpath, rsrc, &dummy, 1); 2795 2796 } 2796 2797 } … … 2860 2861 */ 2861 2862 int sh_files_search_dir(char * name, int * class, 2862 unsigned long *check_ mask, int *reported,2863 unsigned long *check_flags, int *reported, 2863 2864 int * rdepth) 2864 2865 { … … 2877 2878 if (item) 2878 2879 { 2879 *check_ mask = item->check_mask;2880 *check_flags = item->check_flags; 2880 2881 *class = item->class; 2881 2882 *reported = item->is_reported; … … 2892 2893 if (item) 2893 2894 { 2894 *check_ mask = item->check_mask;2895 *check_flags = item->check_flags; 2895 2896 *class = item->class; 2896 2897 *reported = item->is_reported; … … 2914 2915 if (0 == fnmatch(testPattern->name, name, FNM_PATHNAME|FNM_PERIOD)) 2915 2916 { 2916 *check_ mask = testPattern->check_mask;2917 *check_flags = testPattern->check_flags; 2917 2918 *class = testPattern->class; 2918 2919 *rdepth = testPattern->rdepth; … … 2932 2933 2933 2934 int sh_files_search_file(char * name, int * class, 2934 unsigned long *check_ mask, int *reported)2935 unsigned long *check_flags, int *reported) 2935 2936 { 2936 2937 volatile int retval = 0; … … 2946 2947 if (item) 2947 2948 { 2948 *check_ mask = item->check_mask;2949 *check_flags = item->check_flags; 2949 2950 *class = item->class; 2950 2951 *reported = item->is_reported; … … 2966 2967 FNM_PATHNAME|FNM_PERIOD)) 2967 2968 { 2968 *check_ mask = testPattern->check_mask;2969 *check_flags = testPattern->check_flags; 2969 2970 *class = testPattern->class; 2970 2971 retval = 1; … … 3035 3036 { 3036 3037 if (0 == strcmp(name, pfilL->name) && 3037 (pfilL->check_ mask& MODI_ATM) == 0 &&3038 (pfilL->check_ mask& MODI_CTM) == 0 &&3039 (pfilL->check_ mask& MODI_MTM) == 0)3038 (pfilL->check_flags & MODI_ATM) == 0 && 3039 (pfilL->check_flags & MODI_CTM) == 0 && 3040 (pfilL->check_flags & MODI_MTM) == 0) 3040 3041 { 3041 3042 retval = 0; … … 3087 3088 (0 == strncmp(pfilL->name, pdirL->name, dlen))) 3088 3089 { 3089 if ((pdirL->check_ mask& MODI_ATM) != 0 ||3090 (pdirL->check_ mask& MODI_MTM) != 0 ||3091 (pdirL->check_ mask& MODI_CTM) != 0)3090 if ((pdirL->check_flags & MODI_ATM) != 0 || 3091 (pdirL->check_flags & MODI_MTM) != 0 || 3092 (pdirL->check_flags & MODI_CTM) != 0) 3092 3093 { 3093 3094 if (check_file (pdirL->name) != 0)
Note:
See TracChangeset
for help on using the changeset viewer.