# HG changeset patch # User Matti Hamalainen # Date 1352723459 -7200 # Node ID 504a8b9297a3a4473c86ef9dc7db672832c59492 # Parent dd7b58eca06d13a9460cb4cd6f9138e8d4989216 Fix log directory creation. diff -r dd7b58eca06d -r 504a8b9297a3 main.c --- a/main.c Mon Nov 12 14:18:26 2012 +0200 +++ b/main.c Mon Nov 12 14:30:59 2012 +0200 @@ -1579,45 +1579,6 @@ } -BOOL nn_mkdir_rec(const char *cpath) -{ - char save, *path = th_strdup(cpath); - size_t start = 0, end; - BOOL res = FALSE; - - do - { - for (save = 0, end = start; path[end] != 0; end++) - if (path[end] == SET_DIR_SEPARATOR) - { - save = path[end]; - path[end] = 0; - break; - } - - if (path[start] != 0) - { -#ifdef __WIN32 - if (!CreateDirectory(path, NULL)) - goto error; -#else - if (mkdir(path, 711) < 0) - goto error; -#endif - } - - path[end] = save; - start = end + 1; - } while (save != 0); - - res = TRUE; - -error: - th_free(path); - return res; -} - - BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) { #ifdef __WIN32 @@ -1640,6 +1601,55 @@ } +BOOL nn_mkdir_rec(const char *cpath) +{ + char save, *path = th_strdup(cpath); + size_t start = 0, end; + BOOL res = FALSE, exists, isDir, isWritable, isReadable; + + do + { + for (save = 0, end = start; path[end] != 0; end++) + if (path[end] == SET_DIR_SEPARATOR) + { + save = path[end]; + path[end] = 0; + break; + } + + + if (path[start] != 0) + { + exists = nn_stat_path(path, &isDir, &isWritable, &isReadable); + if (exists && !isDir) + goto error; + + if (!exists) + { +#ifdef __WIN32 + if (!CreateDirectory(path, NULL)) + goto error; +#else + if (mkdir(path, 0x1c9) < 0) + goto error; +#endif + } + } + + path[end] = save; + start = end + 1; + } while (save != 0); + + res = TRUE; + +error: + th_free(path); + return res; +} + + + + int main(int argc, char *argv[]) { char *tmpStr; @@ -1769,6 +1779,33 @@ setHomeDir, SET_DIR_SEPARATOR, SET_LOG_DIR, SET_DIR_SEPARATOR); } + { + BOOL isDir, isWritable, isReadable; + if (nn_stat_path(optLogPath, &isDir, &isWritable, &isReadable)) + { + if (!isDir) + { + THERR("The log file path '%s' is not a directory.\n", + optLogPath); + goto err_exit; + } + else + if (!isWritable) + { + THERR("The log file path '%s' is not writable.\n", + optLogPath); + goto err_exit; + } + } + else + if (!nn_mkdir_rec(optLogPath)) + { + THERR("Could not create log file directory '%s'.\n", + optLogPath); + goto err_exit; + } + } + // Parse command line arguments argsOK = th_args_process(argc, argv, optList, optListN, argHandleOpt, argHandleFile, FALSE); @@ -1807,32 +1844,6 @@ if (!optDaemon && !nnwin_init(SET_DELAY)) goto err_exit; - { - BOOL isDir, isWritable, isReadable; - if (nn_stat_path(optLogPath, &isDir, &isWritable, &isReadable)) - { - if (!isDir) - { - errorMsg("The log file path '%s' is not a directory.\n", - optLogPath); - goto err_exit; - } - else - if (!isWritable) - { - errorMsg("The log file path '%s' is not writable.\n", - optLogPath); - goto err_exit; - } - } - else - if (!nn_mkdir_rec(optLogPath)) - { - errorMsg("Could not create log file directory '%s'.\n", - optLogPath); - goto err_exit; - } - } if (cursesInit) {