未验证 提交 0d5151cd 编写于 作者: wafwerar's avatar wafwerar 提交者: GitHub

Merge pull request #11425 from taosdata/fix/ZhiqiangWang/TD-13761-fix-make-mul-dir-error

fix: make mul dir error.
...@@ -38,6 +38,7 @@ typedef struct TdDirEntry *TdDirEntryPtr; ...@@ -38,6 +38,7 @@ typedef struct TdDirEntry *TdDirEntryPtr;
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
bool taosDirExist(char *dirname); bool taosDirExist(char *dirname);
int32_t taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
int32_t taosMulMkDir(const char *dirname);
void taosRemoveOldFiles(const char *dirname, int32_t keepDays); void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
int32_t taosRealPath(char *dirname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen);
......
...@@ -616,7 +616,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -616,7 +616,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
if (taosMkDir(tsLogDir) != 0) { if (taosMulMkDir(tsLogDir) != 0) {
uError("failed to create dir:%s since %s", tsLogDir, terrstr()); uError("failed to create dir:%s since %s", tsLogDir, terrstr());
cfgCleanup(pCfg); cfgCleanup(pCfg);
return -1; return -1;
......
...@@ -76,6 +76,47 @@ int32_t taosMkDir(const char *dirname) { ...@@ -76,6 +76,47 @@ int32_t taosMkDir(const char *dirname) {
return code; return code;
} }
int32_t taosMulMkDir(const char *dirname) {
if (dirname == NULL) return -1;
char *temp = strdup(dirname);
char *pos = temp;
int32_t code = 0;
if (strncmp(temp, "/", 1) == 0) {
pos += 1;
} else if (strncmp(temp, "./", 2) == 0) {
pos += 2;
}
for ( ; *pos != '\0'; pos++) {
if (*pos == '/') {
*pos = '\0';
code = mkdir(temp, 0755);
if (code < 0 && errno != EEXIST) {
free(temp);
return code;
}
*pos = '/';
}
}
if (*(pos - 1) != '/') {
code = mkdir(temp, 0755);
if (code < 0 && errno != EEXIST) {
free(temp);
return code;
}
}
free(temp);
// int32_t code = mkdir(dirname, 0755);
if (code < 0 && errno == EEXIST) {
return 0;
}
return code;
}
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
DIR *dir = opendir(dirname); DIR *dir = opendir(dirname);
if (dir == NULL) return; if (dir == NULL) return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册