Changeset 149 for trunk/src/sh_hash.c
- Timestamp:
- Jan 7, 2008, 8:52:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_hash.c
r137 r149 57 57 #include "sh_files.h" 58 58 #include "sh_ignore.h" 59 #include "sh_pthread.h" 59 60 60 61 #if defined(SH_WITH_CLIENT) … … 69 70 #define FIL__ _("sh_hash.c") 70 71 72 SH_MUTEX_STATIC(mutex_hash,PTHREAD_MUTEX_INITIALIZER); 73 74 const char notalink[2] = { '-', '\0' }; 75 71 76 static char * all_items (file_type * theFile, char * fileHash, int is_new); 72 77 73 78 #define QUOTE_CHAR '=' 74 79 75 char * unquote_string (const char * str )80 char * unquote_string (const char * str, size_t len) 76 81 { 77 82 int i = 0, t1, t2; 78 83 char * tmp = NULL; 79 size_t l en, l2, j, k = 0;84 size_t l2, j, k = 0; 80 85 81 86 SL_ENTER(_("unquote_string")); … … 83 88 if (str != NULL) 84 89 { 85 len = sl_strlen(str);86 90 l2 = len - 2; 87 91 tmp = SH_ALLOC(len + 1); … … 116 120 } 117 121 118 static char i2h[2]; 119 120 char * int2hex (unsigned char i) 122 123 static char * int2hex (unsigned char i, char * i2h) 121 124 { 122 125 static char hexchars[] = "0123456789ABCDEF"; … … 129 132 130 133 131 char * quote_string (const char * str )134 char * quote_string (const char * str, size_t len) 132 135 { 133 136 char * tmp; 134 137 char * tmp2; 135 size_t len, l2, j, i = 0, k = 0; 138 size_t l2, j, i = 0, k = 0; 139 char i2h[2]; 136 140 137 141 SL_ENTER(_("quote_string")); … … 141 145 SL_RETURN(NULL, _("quote_string")); 142 146 } 143 144 len = sl_strlen(str);145 147 146 148 for (j = 0; j < len; ++j) … … 164 166 if (str[j] == '\n') 165 167 { 166 tmp2 = int2hex((unsigned char) '\n' ); /* was 'n', fixed in 1.5.4 */168 tmp2 = int2hex((unsigned char) '\n', i2h); /* was 'n', fixed in 1.5.4 */ 167 169 tmp[k] = QUOTE_CHAR; ++k; 168 170 tmp[k] = tmp2[0]; ++k; … … 171 173 else if (str[j] == QUOTE_CHAR) 172 174 { 173 tmp2 = int2hex((unsigned char) QUOTE_CHAR );175 tmp2 = int2hex((unsigned char) QUOTE_CHAR, i2h); 174 176 tmp[k] = QUOTE_CHAR; ++k; 175 177 tmp[k] = tmp2[0]; ++k; … … 249 251 250 252 typedef struct store_info { 251 /* 252 char fullpath[MAX_PATH_STORE+2]; 253 char linkpath[MAX_PATH_STORE+2]; 254 */ 253 255 254 UINT32 mode; 256 255 UINT32 linkmode; … … 270 269 #if defined(__linux__) 271 270 UINT32 attributes; 272 char c_attributes[ 16];271 char c_attributes[ATTRBUF_SIZE]; 273 272 #endif 274 273 #else 275 274 /* #if defined(__linux__) */ 276 275 UINT32 attributes; 277 char c_attributes[ 16];276 char c_attributes[ATTRBUF_SIZE]; 278 277 /* endif */ 279 278 #endif … … 281 280 char c_owner[USER_MAX+2]; 282 281 char c_group[GROUP_MAX+2]; 283 char c_mode[ 11];282 char c_mode[CMODE_SIZE]; 284 283 char checksum[KEY_LEN+1]; 285 284 } sh_filestore_t; … … 351 350 { 352 351 file_type * theFile; 353 #if defined(__linux__) || defined(HAVE_STAT_FLAGS)354 int i = 16;355 #endif356 352 357 353 SL_ENTER(_("sh_hash_create_ft")); … … 362 358 theFile->mode = p->theFile.mode; 363 359 #if defined(__linux__) || defined(HAVE_STAT_FLAGS) 364 sl_strlcpy(theFile->c_attributes, p->theFile.c_attributes, i /* 16 */);360 sl_strlcpy(theFile->c_attributes, p->theFile.c_attributes, ATTRBUF_SIZE); 365 361 theFile->attributes = p->theFile.attributes; 366 362 #endif … … 431 427 char * str; 432 428 char hashbuf[KEYBUF_SIZE]; 429 int retval = 0; 433 430 434 431 /* -------- find the entry for the file ---------------- */ 432 433 SH_MUTEX_LOCK(mutex_hash); 435 434 436 435 if (sl_strlen(fullpath) <= MAX_PATH_STORE) … … 443 442 ); 444 443 if (p == NULL) 445 return -1; 444 { 445 retval = -1; 446 goto unlock_and_return; 447 } 446 448 447 449 theFile = sh_hash_create_ft (p, fileHash); … … 455 457 SH_FREE(theFile->attr_string); 456 458 SH_FREE(theFile); 457 return 0; 459 460 unlock_and_return: 461 SH_MUTEX_UNLOCK(mutex_hash); 462 return retval; 458 463 } 459 464 … … 564 569 if (p->linkpath) 565 570 { 566 SH_FREE(p->linkpath); 571 if (p->linkpath != notalink) 572 SH_FREE(p->linkpath); 567 573 p->linkpath = NULL; 568 574 } … … 624 630 625 631 SL_ENTER(_("sh_hash_unvisited")); 632 633 SH_MUTEX_LOCK(mutex_hash); 626 634 for (i = 0; i < TABSIZE; ++i) 627 635 { … … 629 637 hash_unvisited (i, tab[i], tab[i], level); 630 638 } 639 SH_MUTEX_UNLOCK(mutex_hash); 640 631 641 SL_RET0(_("hash_unvisited")); 632 642 } … … 655 665 if (p->linkpath) 656 666 { 657 SH_FREE(p->linkpath); 667 if (p->linkpath != notalink) 668 SH_FREE(p->linkpath); 658 669 p->linkpath = NULL; 659 670 } … … 721 732 q = p->next; 722 733 SH_FREE(p->fullpath); 723 if(p->linkpath )734 if(p->linkpath && p->linkpath != notalink) 724 735 SH_FREE(p->linkpath); 725 736 if(p->attr_string) … … 768 779 } 769 780 n = strlen(line); 770 if (n > 1) {781 if (n > 0) { 771 782 --n; 772 783 line[n] = '\0'; /* remove terminating '\n' */ … … 947 958 */ 948 959 i = sh_hash_getline (sh_fin_fd, line, size); 949 if (i < 0 )960 if (i <= 0 ) 950 961 { 951 962 SH_FREE(line); … … 961 972 } 962 973 963 tmp = unquote_string (line );974 tmp = unquote_string (line, i); 964 975 len = sl_strlen(tmp)+1; 965 976 fullpath = SH_ALLOC(len); … … 973 984 */ 974 985 i = sh_hash_getline (sh_fin_fd, line, size); 975 if (i < 0 )986 if (i <= 0 ) 976 987 { 977 988 SH_FREE(line); … … 988 999 } 989 1000 990 tmp = unquote_string (line); 991 len = sl_strlen(tmp)+1; 992 linkpath = SH_ALLOC(len); 993 (void) sl_strlcpy (linkpath, tmp, len); 1001 tmp = unquote_string (line, i); 1002 1003 if ( tmp && tmp[0] == '-' && 1004 (tmp[1] == '\0' || (tmp[1] == '\n' && tmp[2] == '\0'))) 1005 { 1006 linkpath = (char *)notalink; 1007 } 1008 else 1009 { 1010 len = sl_strlen(tmp)+1; 1011 linkpath = SH_ALLOC(len); 1012 (void) sl_strlcpy (linkpath, tmp, len); 1013 if (len > 1 && linkpath[len-2] == '\n') 1014 linkpath[len-2] = '\0'; 1015 } 1016 994 1017 if (tmp) 995 1018 SH_FREE(tmp); 996 if (linkpath[len-2] == '\n')997 linkpath[len-2] = '\0';998 1019 999 1020 /* Read next record -- Part Four -- attr_string … … 1002 1023 { 1003 1024 i = sh_hash_getline (sh_fin_fd, line, size); 1004 if (i < 0 )1025 if (i <= 0 ) 1005 1026 { 1006 1027 SH_FREE(line); 1007 1028 SH_FREE(fullpath); 1008 SH_FREE(linkpath); 1029 if (linkpath != notalink) 1030 SH_FREE(linkpath); 1009 1031 SH_FREE(p); 1010 1032 dlog(1, FIL__, __LINE__, … … 1018 1040 } 1019 1041 1020 tmp = unquote_string (line );1042 tmp = unquote_string (line, i); 1021 1043 1022 1044 len = sl_strlen(tmp)+1; … … 1044 1066 1045 1067 1046 if (ft.c_mode[0] == 'l' )1068 if (ft.c_mode[0] == 'l' && linkpath != notalink) 1047 1069 { 1048 1070 sh_do_decode(linkpath, sl_strlen(linkpath)); … … 1122 1144 SL_ENTER(_("sh_hash_init")); 1123 1145 1124 if (IsInit == 1) 1125 SL_RET0(_("sh_hash_init")); 1126 1127 for (i = 0; i < TABSIZE; ++i) 1128 tab[i] = NULL; 1146 SH_MUTEX_LOCK(mutex_hash); 1147 1148 if (IsInit == 1) 1149 { 1150 goto unlock_and_return; 1151 } 1129 1152 1130 1153 #if defined(SH_WITH_CLIENT) … … 1290 1313 sh_hash_setdataent(fd, line, MAX_PATH_STORE, file_path('D', 'R')); 1291 1314 1315 for (i = 0; i < TABSIZE; ++i) 1316 tab[i] = NULL; 1317 1292 1318 while (1) 1293 1319 { … … 1308 1334 break; 1309 1335 } 1336 1337 /* Initialization completed. 1338 */ 1339 IsInit = 1; 1310 1340 1311 1341 if (line != NULL) … … 1318 1348 fd = -1; 1319 1349 1320 /* --- Initialization done successfully. --- 1321 */ 1322 IsInit = 1; 1350 unlock_and_return: 1351 SH_MUTEX_UNLOCK(mutex_hash); 1323 1352 SL_RET0(_("sh_hash_init")); 1324 1353 } … … 1334 1363 1335 1364 SL_ENTER(_("sh_hash_hashdelete")); 1365 SH_MUTEX_LOCK(mutex_hash); 1336 1366 1337 1367 if (IsInit == 0) 1338 SL_RET0(_("sh_hash_hashdelete")); 1368 goto unlock_and_exit; 1369 1339 1370 for (i = 0; i < TABSIZE; ++i) 1340 1371 if (tab[i] != NULL) … … 1344 1375 } 1345 1376 IsInit = 0; 1377 1378 unlock_and_exit: 1379 SH_MUTEX_UNLOCK(mutex_hash); 1346 1380 SL_RET0(_("sh_hash_hashdelete")); 1347 1381 } … … 1385 1419 1386 1420 1387 void sh_hash_pushdata(file_type * buf, char * fileHash)1421 static void sh_hash_pushdata_int (file_type * buf, char * fileHash) 1388 1422 { 1389 1423 static long p_count = 0; … … 1394 1428 size_t tmp_len = 0; 1395 1429 size_t old_len = 0; 1430 size_t path_len = 0; 1396 1431 1397 1432 sh_filestore_t p; … … 1411 1446 #endif 1412 1447 1413 SL_ENTER(_("sh_hash_pushdata "));1448 SL_ENTER(_("sh_hash_pushdata_int")); 1414 1449 1415 1450 fullpath = SH_ALLOC(MAX_PATH_STORE+1); … … 1432 1467 _("Writing database to stdout with update"), 1433 1468 sh.prg_name, 1434 _("sh_hash_pushdata "));1469 _("sh_hash_pushdata_int")); 1435 1470 aud_exit(FIL__, __LINE__, EXIT_FAILURE); 1436 1471 } … … 1443 1478 _("Writing database to stdout when suid"), 1444 1479 sh.prg_name, 1445 _("sh_hash_pushdata "));1480 _("sh_hash_pushdata_int")); 1446 1481 aud_exit(FIL__, __LINE__, EXIT_FAILURE); 1447 1482 } 1448 1483 1449 1484 1450 if ((pushdata_ stdout == S_FALSE) &&1485 if ((pushdata_isfirst == 1) && (pushdata_stdout == S_FALSE) && 1451 1486 ( (NULL == file_path('D', 'W')) || 1452 1487 (0 == sl_strcmp(file_path('D', 'W'), _("REQ_FROM_SERVER"))) )) … … 1457 1492 _("No local path for database specified"), 1458 1493 sh.prg_name, 1459 _("sh_hash_pushdata "));1494 _("sh_hash_pushdata_int")); 1460 1495 aud_exit(FIL__, __LINE__, EXIT_FAILURE); 1461 1496 } 1462 1497 1463 1498 1464 if ((pushdata_ stdout == S_FALSE) && (pushdata_isfirst == 1))1499 if ((pushdata_isfirst == 1) && (pushdata_stdout == S_FALSE)) 1465 1500 { 1466 1501 /* Warn that file already exists; file_path != NULL here because … … 1488 1523 sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS, 1489 1524 geteuid(), file_path('D', 'W')); 1490 SL_RET0(_("sh_hash_pushdata "));1525 SL_RET0(_("sh_hash_pushdata_int")); 1491 1526 } 1492 1527 if ( SL_ISERROR(status = sl_forward(pushdata_fd))) … … 1495 1530 SH_FREE(linkpath); 1496 1531 sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH, 1497 _("Fast forward failed"), _("sh_hash_pushdata "),1532 _("Fast forward failed"), _("sh_hash_pushdata_int"), 1498 1533 file_path('D', 'W')); 1499 SL_RET0(_("sh_hash_pushdata "));1534 SL_RET0(_("sh_hash_pushdata_int")); 1500 1535 } 1501 1536 } … … 1511 1546 sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS, 1512 1547 geteuid(), file_path('D', 'W')); 1513 SL_RET0(_("sh_hash_pushdata "));1548 SL_RET0(_("sh_hash_pushdata_int")); 1514 1549 } 1515 1550 line = SH_ALLOC(MAX_PATH_STORE+1); … … 1521 1556 SH_FREE(linkpath); 1522 1557 SH_FREE(line); 1523 SL_RET0(_("sh_hash_pushdata "));1558 SL_RET0(_("sh_hash_pushdata_int")); 1524 1559 } 1525 1560 SH_FREE(line); … … 1533 1568 sh_do_encode(buf->fullpath, old_len); 1534 1569 #endif 1535 tmp = quote_string(buf->fullpath );1570 tmp = quote_string(buf->fullpath, old_len); 1536 1571 tmp_len = sl_strlen(tmp); 1537 1572 #if defined(SH_STEALTH) … … 1563 1598 } 1564 1599 1600 path_len = sl_strlen(fullpath); 1565 1601 #if defined(SH_STEALTH) 1566 sh_do_encode(fullpath, sl_strlen(fullpath));1567 #endif 1568 1569 tmp = quote_string(fullpath );1602 sh_do_encode(fullpath, path_len); 1603 #endif 1604 1605 tmp = quote_string(fullpath, path_len); 1570 1606 if (tmp) { 1571 1607 sl_strlcpy(fullpath, tmp, MAX_PATH_STORE+1); … … 1580 1616 sh_do_encode(buf->linkpath, old_len); 1581 1617 #endif 1582 tmp = quote_string(buf->linkpath );1618 tmp = quote_string(buf->linkpath, old_len); 1583 1619 tmp_len = sl_strlen(tmp); 1584 1620 #if defined(SH_STEALTH) … … 1601 1637 if (tmp) SH_FREE(tmp); 1602 1638 1639 path_len = sl_strlen(linkpath); 1603 1640 #if defined(SH_STEALTH) 1604 sh_do_encode(linkpath, sl_strlen(linkpath));1605 #endif 1606 tmp = quote_string(linkpath );1641 sh_do_encode(linkpath, path_len); 1642 #endif 1643 tmp = quote_string(linkpath, path_len); 1607 1644 if (tmp) 1608 1645 { … … 1618 1655 sh_do_encode(buf->attr_string, old_len); 1619 1656 #endif 1620 tmp = quote_string(buf->attr_string );1657 tmp = quote_string(buf->attr_string, old_len); 1621 1658 if (tmp) 1622 1659 { … … 1634 1671 if (attr_string) 1635 1672 p.mark |= REC_FLAGS_ATTR; 1636 sl_strlcpy(p.c_mode, buf->c_mode, 11);1673 sl_strlcpy(p.c_mode, buf->c_mode, CMODE_SIZE); 1637 1674 sl_strlcpy(p.c_group, buf->c_group, GROUP_MAX+1); 1638 1675 sl_strlcpy(p.c_owner, buf->c_owner, USER_MAX+1); … … 1641 1678 } 1642 1679 #if defined(__linux__) || defined(HAVE_STAT_FLAGS) 1643 sl_strlcpy(p.c_attributes, buf->c_attributes, 13);1644 #else 1645 for (i = 0; i < 12; ++i) p.c_attributes[i] = '-';1646 p.c_attributes[ 12] = '\0';1680 sl_strlcpy(p.c_attributes, buf->c_attributes, ATTRBUF_SIZE); 1681 #else 1682 for (i = 0; i < ATTRBUF_USED; ++i) p.c_attributes[i] = '-'; 1683 p.c_attributes[ATTRBUF_USED] = '\0'; 1647 1684 #endif 1648 1685 … … 1778 1815 SH_FREE(attr_string); 1779 1816 1780 SL_RET0(_("sh_hash_pushdata")); 1781 } 1817 SL_RET0(_("sh_hash_pushdata_int")); 1818 } 1819 1820 SH_MUTEX_STATIC(mutex_writeout,PTHREAD_MUTEX_INITIALIZER); 1821 1822 void sh_hash_pushdata (file_type * buf, char * fileHash) 1823 { 1824 SH_MUTEX_LOCK(mutex_writeout); 1825 sh_hash_pushdata_int (buf, fileHash); 1826 SH_MUTEX_UNLOCK(mutex_writeout); 1827 return; 1828 } 1829 1782 1830 1783 1831 int sh_hash_writeout() … … 1797 1845 } 1798 1846 1847 SH_MUTEX_LOCK(mutex_writeout); 1799 1848 if (!SL_ISERROR(pushdata_fd)) 1800 1849 { … … 1804 1853 pushdata_isfirst = 1; 1805 1854 1855 1856 SH_MUTEX_LOCK(mutex_hash); 1806 1857 for (i = 0; i < TABSIZE; ++i) 1807 1858 { … … 1809 1860 { 1810 1861 f = sh_hash_create_ft (p, fileHash); 1811 sh_hash_pushdata (f, fileHash);1862 sh_hash_pushdata_int (f, fileHash); 1812 1863 if (f->attr_string) 1813 1864 SH_FREE(f->attr_string); … … 1815 1866 } 1816 1867 } 1868 SH_MUTEX_UNLOCK(mutex_hash); 1817 1869 1818 1870 if (!SL_ISERROR(pushdata_fd)) … … 1822 1874 } 1823 1875 pushdata_isfirst = 1; 1876 SH_MUTEX_UNLOCK(mutex_writeout); 1824 1877 1825 1878 SL_RETURN (0, _("sh_hash_writeout")); … … 1842 1895 SL_RETURN( (NULL), _("sh_hash_have_it_int")); 1843 1896 1844 if (IsInit != 1)1845 sh_hash_init();1846 1897 if (sl_strlen(newname) <= MAX_PATH_STORE) 1847 1898 p = hashsearch(newname); … … 1851 1902 if (p == NULL) 1852 1903 SL_RETURN( (NULL), _("sh_hash_have_it_int")); 1853 /* 1854 if (p->allignore == S_FALSE && 1855 (p->modi_mask & MODI_CHK) != 0 && 1856 (p->modi_mask & MODI_MOD) != 0) 1857 SL_RETURN( (1), _("sh_hash_have_it")); 1858 */ 1904 1859 1905 SL_RETURN( (p), _("sh_hash_have_it_int")); 1860 1906 } … … 1862 1908 int sh_hash_have_it (char * newname) 1863 1909 { 1864 sh_file_t * p = sh_hash_have_it_int (newname); 1865 1866 if (!p) return (-1); 1867 if ((!SH_FFLAG_ALLIGNORE_SET(p->fflags)) && 1868 (p->modi_mask & MODI_CHK) != 0 && 1869 (p->modi_mask & MODI_MOD) != 0) 1870 return 1; 1871 return 0; 1910 sh_file_t * p; 1911 int retval = 0; 1912 1913 if (IsInit != 1) 1914 sh_hash_init(); 1915 1916 SH_MUTEX_LOCK(mutex_hash); 1917 p = sh_hash_have_it_int (newname); 1918 1919 if (!p) 1920 retval = (-1); 1921 else if ((!SH_FFLAG_ALLIGNORE_SET(p->fflags)) && 1922 (p->modi_mask & MODI_CHK) != 0 && 1923 (p->modi_mask & MODI_MOD) != 0) 1924 retval = 1; 1925 SH_MUTEX_UNLOCK(mutex_hash); 1926 1927 return retval; 1872 1928 } 1873 1929 1874 1930 int sh_hash_get_it (char * newname, file_type * tmpFile) 1875 1931 { 1876 sh_file_t * p = sh_hash_have_it_int (newname); 1877 if (!p) 1878 return (-1); 1879 sl_strlcpy(tmpFile->fullpath, p->fullpath, PATH_MAX); 1880 sl_strlcpy(tmpFile->linkpath, p->linkpath, PATH_MAX); 1881 tmpFile->size = p->theFile.size; 1882 tmpFile->mtime = p->theFile.mtime; 1883 tmpFile->ctime = p->theFile.ctime; 1884 1885 tmpFile->attr_string = NULL; 1886 return 0; 1932 sh_file_t * p; 1933 int retval = -1; 1934 1935 if (IsInit != 1) 1936 sh_hash_init(); 1937 1938 SH_MUTEX_LOCK(mutex_hash); 1939 p = sh_hash_have_it_int (newname); 1940 if (p) 1941 { 1942 sl_strlcpy(tmpFile->fullpath, p->fullpath, PATH_MAX); 1943 sl_strlcpy(tmpFile->linkpath, p->linkpath, PATH_MAX); 1944 tmpFile->size = p->theFile.size; 1945 tmpFile->mtime = p->theFile.mtime; 1946 tmpFile->ctime = p->theFile.ctime; 1947 tmpFile->attr_string = NULL; 1948 retval = 0; 1949 } 1950 SH_MUTEX_UNLOCK(mutex_hash); 1951 1952 return retval; 1887 1953 } 1888 1954 1889 1955 int sh_hash_getflags (char * filename) 1890 1956 { 1891 sh_file_t * p = sh_hash_have_it_int (filename); 1892 if (!p) 1893 return (-1); 1894 return (p->fflags); 1957 sh_file_t * p; 1958 int retval = -1; 1959 1960 if (IsInit != 1) 1961 sh_hash_init(); 1962 1963 SH_MUTEX_LOCK(mutex_hash); 1964 p = sh_hash_have_it_int (filename); 1965 if (p) 1966 retval = p->fflags; 1967 SH_MUTEX_UNLOCK(mutex_hash); 1968 return retval; 1895 1969 } 1896 1970 1897 1971 int sh_hash_setflags (char * filename, int flags) 1898 1972 { 1899 sh_file_t * p = sh_hash_have_it_int (filename); 1900 if (!p) 1901 return (-1); 1902 p->fflags = flags; 1903 return 0; 1973 sh_file_t * p; 1974 int retval = -1; 1975 1976 if (IsInit != 1) 1977 sh_hash_init(); 1978 1979 SH_MUTEX_LOCK(mutex_hash); 1980 p = sh_hash_have_it_int (filename); 1981 if (p) 1982 { 1983 p->fflags = flags; 1984 retval = 0; 1985 } 1986 SH_MUTEX_UNLOCK(mutex_hash); 1987 return retval; 1904 1988 } 1905 1989 … … 1908 1992 void sh_hash_addflag (char * filename, int flag_to_set) 1909 1993 { 1910 int fflags = sh_hash_getflags(filename); 1911 1912 if (fflags >= 0) 1913 { 1914 fflags |= flag_to_set; 1915 sh_hash_setflags(filename, fflags); 1916 } 1994 sh_file_t * p; 1995 1996 if (IsInit != 1) 1997 sh_hash_init(); 1998 1999 SH_MUTEX_LOCK(mutex_hash); 2000 p = sh_hash_have_it_int (filename); 2001 if (p) 2002 { 2003 p->fflags |= flag_to_set; 2004 } 2005 SH_MUTEX_UNLOCK(mutex_hash); 1917 2006 return; 1918 2007 } … … 1929 2018 sh_file_t * p; 1930 2019 char hashbuf[KEYBUF_SIZE]; 2020 int retval = -1; 1931 2021 1932 2022 SL_ENTER(_("sh_hash_set_visited_int")); … … 1934 2024 if (newname == NULL) 1935 2025 SL_RETURN((-1), _("sh_hash_set_visited_int")); 2026 1936 2027 if (IsInit != 1) 1937 2028 sh_hash_init(); 2029 2030 SH_MUTEX_LOCK(mutex_hash); 1938 2031 1939 2032 if (sl_strlen(newname) <= MAX_PATH_STORE) … … 1943 2036 hashbuf, sizeof(hashbuf))); 1944 2037 1945 if (p == NULL) 1946 SL_RETURN((-1), _("sh_hash_set_visited_int")); 1947 1948 if (flag == SH_FFLAG_CHECKED) 1949 { 1950 CLEAR_SH_FFLAG_REPORTED(p->fflags); 1951 CLEAR_SH_FFLAG_VISITED(p->fflags); 1952 SET_SH_FFLAG_CHECKED(p->fflags); 1953 } 1954 else 1955 { 1956 SET_SH_FFLAG_VISITED(p->fflags); 1957 CLEAR_SH_FFLAG_CHECKED(p->fflags); 1958 if (flag == SH_FFLAG_REPORTED) 1959 SET_SH_FFLAG_REPORTED(p->fflags); 2038 if (p) 2039 { 2040 if (flag == SH_FFLAG_CHECKED) 2041 { 2042 CLEAR_SH_FFLAG_REPORTED(p->fflags); 2043 CLEAR_SH_FFLAG_VISITED(p->fflags); 2044 SET_SH_FFLAG_CHECKED(p->fflags); 2045 } 1960 2046 else 1961 CLEAR_SH_FFLAG_REPORTED(p->fflags); 1962 } 1963 SL_RETURN((0), _("sh_hash_set_visited_int")); 2047 { 2048 SET_SH_FFLAG_VISITED(p->fflags); 2049 CLEAR_SH_FFLAG_CHECKED(p->fflags); 2050 if (flag == SH_FFLAG_REPORTED) 2051 SET_SH_FFLAG_REPORTED(p->fflags); 2052 else 2053 CLEAR_SH_FFLAG_REPORTED(p->fflags); 2054 } 2055 retval = 0; 2056 } 2057 2058 SH_MUTEX_UNLOCK(mutex_hash); 2059 SL_RETURN((retval), _("sh_hash_set_visited_int")); 1964 2060 } 1965 2061 … … 2590 2686 if (p) 2591 2687 { 2688 SH_MUTEX_LOCK(mutex_hash); 2592 2689 hashinsert (p); 2593 2690 p->modi_mask = theFile->check_mask; 2691 SH_MUTEX_UNLOCK(mutex_hash); 2594 2692 } 2595 2693 … … 2633 2731 char hashbuf[KEYBUF_SIZE]; 2634 2732 2733 int retval = 0; 2734 2635 2735 SL_ENTER(_("sh_hash_compdata")); 2636 2736 … … 2646 2746 2647 2747 /* -------- find the entry for the file ---------------- */ 2748 2749 SH_MUTEX_LOCK(mutex_hash); 2648 2750 2649 2751 if (sl_strlen(theFile->fullpath) <= MAX_PATH_STORE) … … 2675 2777 } 2676 2778 2677 if (p)2678 {2679 SET_SH_FFLAG_VISITED(p->fflags);2680 CLEAR_SH_FFLAG_CHECKED(p->fflags);2681 }2682 2683 2779 if (sh.flag.reportonce == S_TRUE) 2684 2780 SET_SH_FFLAG_REPORTED(theFile->file_reported); … … 2687 2783 { 2688 2784 p = sh_hash_push_int(theFile, fileHash); 2689 hashinsert (p);2690 2785 if (p) 2691 p->modi_mask = theFile->check_mask; 2786 { 2787 hashinsert (p); 2788 p->modi_mask = theFile->check_mask; 2789 } 2692 2790 } 2693 2791 … … 2697 2795 { 2698 2796 p = sh_hash_push_int(theFile, fileHash); 2699 hashinsert (p);2700 2797 if (p) 2701 p->modi_mask = theFile->check_mask; 2798 { 2799 hashinsert (p); 2800 p->modi_mask = theFile->check_mask; 2801 } 2702 2802 } 2703 2803 else 2704 2804 { 2705 SL_RETURN(1, _("sh_hash_compdata")); 2805 retval = 1; 2806 goto unlock_and_return; 2706 2807 } 2707 2808 } 2708 2709 SL_RETURN(0, _("sh_hash_compdata")); 2710 } 2711 else 2712 { 2713 p->modi_mask = theFile->check_mask; 2714 } 2809 2810 goto unlock_and_return; 2811 } 2812 2813 p->modi_mask = theFile->check_mask; 2715 2814 2716 2815 /* initialize change_code */ … … 3251 3350 if (sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE) 3252 3351 { 3253 if (p->linkpath != NULL )3352 if (p->linkpath != NULL && p->linkpath != notalink) 3254 3353 SH_FREE(p->linkpath); 3255 p->linkpath = sh_util_strdup(theFile->linkpath); 3354 if (theFile->linkpath[0] == '-' && theFile->linkpath[1] == '\0') 3355 p->linkpath = (char *)notalink; 3356 else 3357 p->linkpath = sh_util_strdup(theFile->linkpath); 3256 3358 } 3257 3359 #endif … … 3331 3433 SET_SH_FFLAG_VISITED(p->fflags); 3332 3434 CLEAR_SH_FFLAG_CHECKED(p->fflags); 3333 SL_RETURN(1, _("sh_hash_compdata")); 3435 retval = 1; 3436 goto unlock_and_return; 3334 3437 } 3335 3438 else /* if (sh.flag.reportonce == S_TRUE) */ … … 3362 3465 if (theFile->c_mode[0] == 'l') 3363 3466 { 3364 if (p->linkpath != NULL )3467 if (p->linkpath != NULL && p->linkpath != notalink) 3365 3468 SH_FREE(p->linkpath); 3366 3469 p->linkpath = sh_util_strdup(theFile->linkpath); … … 3368 3471 else 3369 3472 { 3370 if (p->linkpath != NULL ) {3473 if (p->linkpath != NULL && p->linkpath != notalink) { 3371 3474 p->linkpath[0] = '-'; 3372 3475 p->linkpath[1] = '\0'; 3373 3476 } else { 3374 p->linkpath = SH_ALLOC(2); 3375 p->linkpath[0] = '-'; 3376 p->linkpath[1] = '\0'; 3477 p->linkpath = (char *)notalink; 3377 3478 } 3378 3479 } … … 3402 3503 CLEAR_SH_FFLAG_CHECKED(p->fflags); 3403 3504 3404 SL_RETURN(0, _("sh_hash_compdata")); 3505 unlock_and_return: 3506 3507 SH_MUTEX_UNLOCK(mutex_hash); 3508 SL_RETURN(retval, _("sh_hash_compdata")); 3405 3509 } 3406 3510 … … 3415 3519 SL_RETURN(0, _("sh_hash_compdata")); 3416 3520 3521 SH_MUTEX_LOCK_UNSAFE(mutex_hash); 3417 3522 for (i = 0; i < TABSIZE; ++i) 3418 3523 { … … 3420 3525 CLEAR_SH_FFLAG_ALLIGNORE(p->fflags); 3421 3526 } 3527 SH_MUTEX_UNLOCK_UNSAFE(mutex_hash); 3422 3528 SL_RETURN (0, _("sh_hash_compdata")); 3423 3529 } … … 3440 3546 sh_hash_init(); 3441 3547 3548 SH_MUTEX_LOCK_UNSAFE(mutex_hash); 3442 3549 for (i = 0; i < TABSIZE; ++i) 3443 3550 { … … 3450 3557 } 3451 3558 } 3559 SH_MUTEX_UNLOCK_UNSAFE(mutex_hash); 3452 3560 SL_RETURN ((0), _("hash_remove_tree")); 3453 3561 } … … 3469 3577 int set_full_detail (const char * c) 3470 3578 { 3579 (void) c; 3471 3580 ListFullDetail = S_TRUE; 3472 /* warning: unused parameter `c' */ 3473 if (c) 3474 return 0; 3475 else 3476 return 0; 3581 return 0; 3477 3582 } 3478 3583 3479 3584 int set_list_delimited (const char * c) 3480 3585 { 3586 (void) c; 3481 3587 ListFullDetail = S_TRUE; 3482 3588 ListWithDelimiter = S_TRUE; 3483 /* warning: unused parameter `c' */ 3484 if (c) 3485 return 0; 3486 else 3487 return 0; 3488 } 3489 3490 /* Always quote the string, except if it is empty. Qoute quotes by 3589 return 0; 3590 } 3591 3592 /* Always quote the string, except if it is empty. Quote quotes by 3491 3593 * doubling them. 3492 3594 */
Note:
See TracChangeset
for help on using the changeset viewer.