Changeset 227 for trunk/src/sh_files.c
- Timestamp:
- Apr 20, 2009, 5:59:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_files.c
r171 r227 1489 1489 int status; 1490 1490 int dummy = S_FALSE; 1491 dir_type 1491 dir_type * theDir; 1492 1492 ShFileType checkit; 1493 1493 static unsigned int state = 1; 1494 1494 1495 file_type 1495 file_type * theFile; 1496 1496 char * tmpname; 1497 1497 char * tmpcat; … … 1571 1571 /* ---- stat the directory ---- 1572 1572 */ 1573 sl_strlcpy (theFile.fullpath, iname, PATH_MAX); 1574 theFile.attr_string = NULL; 1575 theFile.link_path = NULL; 1573 theFile = SH_ALLOC(sizeof(file_type)); 1574 sl_strlcpy (theFile->fullpath, iname, PATH_MAX); 1575 theFile->attr_string = NULL; 1576 theFile->link_path = NULL; 1576 1577 1577 1578 (void) relativeName; 1578 1579 status = sh_unix_getinfo (ShDFLevel[SH_ERR_T_DIR], 1579 1580 iname, 1580 &theFile, NULL, iclass);1581 theFile, NULL, iclass); 1581 1582 1582 1583 if ((sig_termfast == 1) || (sig_terminate == 1)) 1583 1584 { 1584 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1585 if (theFile.link_path) SH_FREE(theFile.link_path); 1585 if (theFile->attr_string) SH_FREE(theFile->attr_string); 1586 if (theFile->link_path) SH_FREE(theFile->link_path); 1587 SH_FREE(theFile); 1586 1588 SL_RETURN((0), _("sh_files_checkdir")); 1587 1589 } … … 1590 1592 { 1591 1593 SH_FREE(tmpname); 1592 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1593 if (theFile.link_path) SH_FREE(theFile.link_path); 1594 SL_RETURN((-1), _("sh_files_checkdir")); 1595 } 1596 1597 if (theFile.c_mode[0] != 'd') 1594 if (theFile->attr_string) SH_FREE(theFile->attr_string); 1595 if (theFile->link_path) SH_FREE(theFile->link_path); 1596 SH_FREE(theFile); 1597 SL_RETURN((-1), _("sh_files_checkdir")); 1598 } 1599 1600 if (theFile->c_mode[0] != 'd') 1598 1601 { 1599 1602 sh_error_handle (ShDFLevel[SH_ERR_T_DIR], FIL__, __LINE__, 0, … … 1601 1604 tmpname); 1602 1605 SH_FREE(tmpname); 1603 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1604 if (theFile.link_path) SH_FREE(theFile.link_path); 1606 if (theFile->attr_string) SH_FREE(theFile->attr_string); 1607 if (theFile->link_path) SH_FREE(theFile->link_path); 1608 SH_FREE(theFile); 1605 1609 SL_RETURN((-1), _("sh_files_checkdir")); 1606 1610 } 1607 1611 1608 hardlink_num = theFile.hardlinks; 1609 1612 hardlink_num = theFile->hardlinks; 1613 1614 if (theFile->attr_string) SH_FREE(theFile->attr_string); 1615 if (theFile->link_path) SH_FREE(theFile->link_path); 1616 SH_FREE(theFile); 1610 1617 1611 1618 /* ---- open directory for reading ---- … … 1623 1630 sh_error_message (status, errbuf, sizeof(errbuf)), tmpname); 1624 1631 SH_FREE(tmpname); 1625 1626 if (theFile.attr_string) SH_FREE(theFile.attr_string);1627 if (theFile.link_path) SH_FREE(theFile.link_path);1628 1632 SL_RETURN((-1), _("sh_files_checkdir")); 1629 1633 } 1630 1634 1631 theDir.NumRegular = 0; 1632 theDir.NumDirs = 0; 1633 theDir.NumSymlinks = 0; 1634 theDir.NumFifos = 0; 1635 theDir.NumSockets = 0; 1636 theDir.NumCDev = 0; 1637 theDir.NumBDev = 0; 1638 theDir.NumDoor = 0; 1639 theDir.NumPort = 0; 1640 theDir.NumAll = 0; 1641 theDir.TotalBytes = 0; 1642 sl_strlcpy (theDir.DirPath, iname, PATH_MAX); 1635 theDir = SH_ALLOC(sizeof(dir_type)); 1636 1637 theDir->NumRegular = 0; 1638 theDir->NumDirs = 0; 1639 theDir->NumSymlinks = 0; 1640 theDir->NumFifos = 0; 1641 theDir->NumSockets = 0; 1642 theDir->NumCDev = 0; 1643 theDir->NumBDev = 0; 1644 theDir->NumDoor = 0; 1645 theDir->NumPort = 0; 1646 theDir->NumAll = 0; 1647 theDir->TotalBytes = 0; 1648 sl_strlcpy (theDir->DirPath, iname, PATH_MAX); 1643 1649 1644 1650 … … 1654 1660 if (thisEntry != NULL) 1655 1661 { 1656 ++theDir .NumAll;1662 ++theDir->NumAll; 1657 1663 if (sl_strcmp (thisEntry->d_name, ".") == 0) 1658 1664 { 1659 ++theDir .NumDirs;1665 ++theDir->NumDirs; 1660 1666 continue; 1661 1667 } 1662 1668 if (sl_strcmp (thisEntry->d_name, "..") == 0) 1663 1669 { 1664 ++theDir .NumDirs;1670 ++theDir->NumDirs; 1665 1671 continue; 1666 1672 } … … 1686 1692 if (sig_termfast == 1) 1687 1693 { 1688 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1689 if (theFile.link_path) SH_FREE(theFile.link_path); 1694 SH_FREE(theDir); 1690 1695 SL_RETURN((0), _("sh_files_checkdir")); 1691 1696 } … … 1769 1774 if (checkit == SH_FILE_DIRECTORY) 1770 1775 { 1771 ++theDir .NumDirs;1776 ++theDir->NumDirs; 1772 1777 } 1773 1778 SH_FREE(tmpcat); … … 1805 1810 1806 1811 if (checkit == SH_FILE_REGULAR) 1807 ++theDir .NumRegular;1812 ++theDir->NumRegular; 1808 1813 1809 1814 else if (checkit == SH_FILE_DIRECTORY) 1810 1815 { 1811 ++theDir .NumDirs;1816 ++theDir->NumDirs; 1812 1817 if (rdepth_next >= 0 && cchecked_flag != S_TRUE) 1813 1818 { … … 1870 1875 } 1871 1876 1872 else if (checkit == SH_FILE_SYMLINK) ++theDir .NumSymlinks;1873 else if (checkit == SH_FILE_FIFO) ++theDir .NumFifos;1874 else if (checkit == SH_FILE_SOCKET) ++theDir .NumSockets;1875 else if (checkit == SH_FILE_CDEV) ++theDir .NumCDev;1876 else if (checkit == SH_FILE_BDEV) ++theDir .NumBDev;1877 else if (checkit == SH_FILE_DOOR) ++theDir .NumDoor;1878 else if (checkit == SH_FILE_PORT) ++theDir .NumPort;1877 else if (checkit == SH_FILE_SYMLINK) ++theDir->NumSymlinks; 1878 else if (checkit == SH_FILE_FIFO) ++theDir->NumFifos; 1879 else if (checkit == SH_FILE_SOCKET) ++theDir->NumSockets; 1880 else if (checkit == SH_FILE_CDEV) ++theDir->NumCDev; 1881 else if (checkit == SH_FILE_BDEV) ++theDir->NumBDev; 1882 else if (checkit == SH_FILE_DOOR) ++theDir->NumDoor; 1883 else if (checkit == SH_FILE_PORT) ++theDir->NumPort; 1879 1884 1880 1885 SH_FREE(tmpcat); … … 1882 1887 if ((sig_termfast == 1) || (sig_terminate == 1)) 1883 1888 { 1884 if (theFile.attr_string) SH_FREE(theFile.attr_string); 1885 if (theFile.link_path) SH_FREE(theFile.link_path); 1889 SH_FREE(theDir); 1886 1890 SL_RETURN((0), _("sh_files_checkdir")); 1887 1891 } … … 1897 1901 { 1898 1902 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DSUM, 1899 theDir .NumDirs,1900 theDir .NumRegular,1901 theDir .NumSymlinks,1902 theDir .NumFifos,1903 theDir .NumSockets,1904 theDir .NumCDev,1905 theDir .NumBDev);1903 theDir->NumDirs, 1904 theDir->NumRegular, 1905 theDir->NumSymlinks, 1906 theDir->NumFifos, 1907 theDir->NumSockets, 1908 theDir->NumCDev, 1909 theDir->NumBDev); 1906 1910 } 1907 1911 … … 1912 1916 * Hardlink check; not done on MacOS X because of resource forks 1913 1917 */ 1914 if ((sh_check_hardlinks == S_TRUE) && (hardlink_num != theDir .NumDirs))1915 { 1916 if (0 != sh_files_hle_test(hardlink_num-theDir .NumDirs, iname))1918 if ((sh_check_hardlinks == S_TRUE) && (hardlink_num != theDir->NumDirs)) 1919 { 1920 if (0 != sh_files_hle_test(hardlink_num-theDir->NumDirs, iname)) 1917 1921 { 1918 1922 len = strlen(tmpname); … … 1922 1926 sl_snprintf(tmpcat, len, 1923 1927 _("%s: subdirectory count (%d) != hardlinks (%d)"), 1924 tmpname, theDir .NumDirs, hardlink_num);1928 tmpname, theDir->NumDirs, hardlink_num); 1925 1929 sh_error_handle (ShDFLevel[SH_ERR_T_DIR], FIL__, __LINE__, 0, 1926 1930 MSG_E_SUBGEN, tmpcat, _("sh_files_checkdir")); … … 1930 1934 #endif 1931 1935 1932 if (theFile.attr_string) SH_FREE(theFile.attr_string);1933 if (theFile.link_path) SH_FREE(theFile.link_path);1934 1936 SH_FREE(tmpname); 1937 SH_FREE(theDir); 1935 1938 1936 1939 SL_RETURN((0), _("sh_files_checkdir")); … … 1947 1950 /* 28 Aug 2001 allow NULL fileName 1948 1951 */ 1949 char fullpath[PATH_MAX];1952 char * fullpath; 1950 1953 char fileHash[2*(KEY_LEN + 1)]; 1951 1954 int status; 1952 file_type 1955 file_type * theFile; 1953 1956 char * tmpdir; 1954 1957 char * tmpname; … … 1956 1959 struct utimbuf utime_buf; 1957 1960 static unsigned int state = 1; 1961 char sc; 1958 1962 1959 1963 SL_ENTER(_("sh_files_filecheck")); 1964 1965 fullpath = SH_ALLOC(PATH_MAX); 1966 theFile = SH_ALLOC(sizeof(file_type)); 1960 1967 1961 1968 BREAKEXIT(sh_derr); … … 1982 1989 { 1983 1990 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_NULL); 1991 SH_FREE(fullpath); 1992 SH_FREE(theFile); 1984 1993 SL_RETURN(SH_FILE_UNKNOWN, _("sh_files_filecheck")); 1985 1994 } … … 2020 2029 SH_FREE(tmpname); 2021 2030 SH_FREE(tmpdir); 2031 SH_FREE(fullpath); 2032 SH_FREE(theFile); 2022 2033 SL_RETURN(SH_FILE_UNKNOWN, _("sh_files_filecheck")); 2023 2034 } … … 2026 2037 /* stat the file and determine checksum (if a regular file) 2027 2038 */ 2028 sl_strlcpy (theFile .fullpath, fullpath, PATH_MAX);2029 theFile .check_mask = sh_files_maskof(class);2030 theFile .file_reported = (*reported);2031 theFile .attr_string = NULL;2032 theFile .link_path = NULL;2039 sl_strlcpy (theFile->fullpath, fullpath, PATH_MAX); 2040 theFile->check_mask = sh_files_maskof(class); 2041 theFile->file_reported = (*reported); 2042 theFile->attr_string = NULL; 2043 theFile->link_path = NULL; 2033 2044 2034 2045 TPT(( 0, FIL__, __LINE__, _("msg=<checking file: %s>\n"), fullpath)); … … 2037 2048 ShDFLevel[class] : ShDFLevel[SH_ERR_T_FILE], 2038 2049 fileName, 2039 &theFile, fileHash, class);2050 theFile, fileHash, class); 2040 2051 2041 2052 if (status != 0) … … 2045 2056 if (class == SH_LEVEL_ALLIGNORE && sh.flag.checkSum != SH_CHECK_INIT) 2046 2057 sh_hash_set_visited_true (fullpath); 2047 if (theFile.attr_string) SH_FREE(theFile.attr_string); 2048 if (theFile.link_path) SH_FREE(theFile.link_path); 2058 if (theFile->attr_string) SH_FREE(theFile->attr_string); 2059 if (theFile->link_path) SH_FREE(theFile->link_path); 2060 SH_FREE(fullpath); 2061 SH_FREE(theFile); 2049 2062 SL_RETURN(SH_FILE_UNKNOWN, _("sh_files_filecheck")); 2050 2063 } … … 2056 2069 /* report 2057 2070 */ 2058 if ((flag_err_debug == SL_TRUE) && (theFile .c_mode[0] == '-'))2071 if ((flag_err_debug == SL_TRUE) && (theFile->c_mode[0] == '-')) 2059 2072 { 2060 2073 tmpname = sh_util_safe_name (fullpath); /* fixed in 1.5.4 */ … … 2067 2080 if ( sh.flag.checkSum == SH_CHECK_INIT /* && sh.flag.update == S_FALSE */) 2068 2081 { 2069 sh_hash_pushdata ( &theFile, fileHash);2082 sh_hash_pushdata (theFile, fileHash); 2070 2083 } 2071 2084 else if (sh.flag.checkSum == SH_CHECK_CHECK … … 2074 2087 ) 2075 2088 { 2076 sh_hash_compdata (class, &theFile, fileHash, NULL, -1);2089 sh_hash_compdata (class, theFile, fileHash, NULL, -1); 2077 2090 } 2078 2091 2079 (*reported) = theFile .file_reported;2092 (*reported) = theFile->file_reported; 2080 2093 2081 2094 /* reset the access time 2082 2095 */ 2083 if (class == SH_LEVEL_NOIGNORE && (theFile .check_mask & MODI_ATM) != 0)2084 { 2085 utime_buf.actime = (time_t) theFile .atime;2086 utime_buf.modtime = (time_t) theFile .mtime;2096 if (class == SH_LEVEL_NOIGNORE && (theFile->check_mask & MODI_ATM) != 0) 2097 { 2098 utime_buf.actime = (time_t) theFile->atime; 2099 utime_buf.modtime = (time_t) theFile->mtime; 2087 2100 #if !defined(O_NOATIME) 2088 2101 retry_aud_utime (FIL__, __LINE__, fullpath, &utime_buf); … … 2094 2107 * Check for resource fork 2095 2108 */ 2096 if ( (theFile .c_mode[0] != 'd') && (rsrcflag == 0) )2109 if ( (theFile->c_mode[0] != 'd') && (rsrcflag == 0) ) 2097 2110 { 2098 2111 int dummy; 2099 2112 static int rsrc_init = 0; 2100 2113 static char rsrc[17]; 2101 char testpath [PATH_MAX];2114 char testpath = SH_ALLOC(PATH_MAX); 2102 2115 2103 2116 if (rsrc_init == 0) { … … 2116 2129 } 2117 2130 } 2131 SH_FREE(testpath); 2118 2132 } 2119 2133 #else … … 2123 2137 ret_point: 2124 2138 2125 if (theFile.attr_string) SH_FREE(theFile.attr_string); 2126 if (theFile.link_path) SH_FREE(theFile.link_path); 2127 2128 switch (theFile.c_mode[0]) 2139 sc = theFile->c_mode[0]; 2140 2141 if (theFile->attr_string) SH_FREE(theFile->attr_string); 2142 if (theFile->link_path) SH_FREE(theFile->link_path); 2143 SH_FREE(fullpath); 2144 SH_FREE(theFile); 2145 2146 switch (sc) 2129 2147 { 2130 2148 case '-': SL_RETURN(SH_FILE_REGULAR, _("sh_files_filecheck"));
Note:
See TracChangeset
for help on using the changeset viewer.