fix: make mul dir error.

This commit is contained in:
afwerar 2022-04-12 19:05:43 +08:00
parent 684a1f23ad
commit f937c5b889
1 changed files with 33 additions and 1 deletions

View File

@ -68,7 +68,39 @@ void taosRemoveDir(const char *dirname) {
bool taosDirExist(char *dirname) { return taosCheckExistFile(dirname); }
int32_t taosMkDir(const char *dirname) {
int32_t code = mkdir(dirname, 0755);
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;
}