comparison main.c @ 557:02244c553741

Fix Win32 side of log directory creation.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 13 Nov 2012 01:06:26 +0200
parents 9b72d0060b85
children e32881ece842
comparison
equal deleted inserted replaced
556:9b72d0060b85 557:02244c553741
1659 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) 1659 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable)
1660 { 1660 {
1661 #ifdef __WIN32 1661 #ifdef __WIN32
1662 DWORD attr = GetFileAttributes(path); 1662 DWORD attr = GetFileAttributes(path);
1663 1663
1664 *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY); 1664 *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
1665 *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0 && *isDirectory == FALSE; 1665 *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0;
1666 *isReadable = TRUE; 1666 *isReadable = TRUE;
1667 #else 1667 #else
1668 uid_t id = geteuid(); 1668 uid_t id = geteuid();
1669 struct stat sb; 1669 struct stat sb;
1670 if (stat(path, &sb) < 0) 1670 if (stat(path, &sb) < 0)
1672 1672
1673 *isDirectory = (S_ISDIR(sb.st_mode)); 1673 *isDirectory = (S_ISDIR(sb.st_mode));
1674 *isWritable = (id == sb.st_uid && (sb.st_mode & S_IWUSR)); 1674 *isWritable = (id == sb.st_uid && (sb.st_mode & S_IWUSR));
1675 *isReadable = (id == sb.st_uid && (sb.st_mode & S_IRUSR)); 1675 *isReadable = (id == sb.st_uid && (sb.st_mode & S_IRUSR));
1676 #endif 1676 #endif
1677
1678 THERR("'%s': dir=%d, wr=%d, rd=%d\n",
1679 path, *isDirectory, *isWritable, *isReadable);
1677 return TRUE; 1680 return TRUE;
1678 } 1681 }
1679 1682
1680 1683
1681 BOOL nn_mkdir_rec(const char *cpath) 1684 BOOL nn_mkdir_rec(const char *cpath)
1682 { 1685 {
1683 char save, *path = th_strdup(cpath); 1686 char save, *path = th_strdup(cpath);
1684 size_t start = 0, end; 1687 size_t start = 0, end;
1685 BOOL res = FALSE, exists, isDir, isWritable, isReadable; 1688 BOOL res = FALSE, exists, isDir, isWritable, isReadable;
1686 1689
1690 THMSG(0, "Creating directory %s\n", cpath);
1687 do 1691 do
1688 { 1692 {
1689 for (save = 0, end = start; path[end] != 0; end++) 1693 for (save = 0, end = start; path[end] != 0; end++)
1690 if (path[end] == SET_DIR_SEPARATOR) 1694 if (path[end] == SET_DIR_SEPARATOR)
1691 { 1695 {
1871 goto err_exit; 1875 goto err_exit;
1872 } 1876 }
1873 else 1877 else
1874 if (!isWritable) 1878 if (!isWritable)
1875 { 1879 {
1880 #ifdef __WIN32
1881 if (!nn_mkdir_rec(optLogPath))
1882 {
1883 THERR("Could not create log file directory '%s'.\n",
1884 optLogPath);
1885 goto err_exit;
1886 }
1887 #else
1876 THERR("The log file path '%s' is not writable.\n", 1888 THERR("The log file path '%s' is not writable.\n",
1877 optLogPath); 1889 optLogPath);
1878 goto err_exit; 1890 goto err_exit;
1891 #endif
1879 } 1892 }
1880 } 1893 }
1881 else 1894 else
1882 if (!nn_mkdir_rec(optLogPath)) 1895 if (!nn_mkdir_rec(optLogPath))
1883 { 1896 {