os: chmod log dir mode
This commit is contained in:
parent
515ca0cbf7
commit
6759a38a8d
|
@ -56,6 +56,7 @@ void taosRemoveDir(const char *dirname);
|
|||
bool taosDirExist(const char *dirname);
|
||||
int32_t taosMkDir(const char *dirname);
|
||||
int32_t taosMulMkDir(const char *dirname);
|
||||
int32_t taosMulModeMkDir(const char *dirname, int mode);
|
||||
void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
|
||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
|
||||
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen);
|
||||
|
|
|
@ -1129,7 +1129,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
|
||||
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false);
|
||||
|
||||
if (taosMulMkDir(tsLogDir) != 0) {
|
||||
if (taosMulModeMkDir(tsLogDir, 0777) != 0) {
|
||||
uError("failed to create dir:%s since %s", tsLogDir, terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
|
|
|
@ -160,6 +160,66 @@ int32_t taosMulMkDir(const char *dirname) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t taosMulModeMkDir(const char *dirname, int mode) {
|
||||
if (dirname == NULL) return -1;
|
||||
char temp[1024];
|
||||
char *pos = temp;
|
||||
int32_t code = 0;
|
||||
#ifdef WINDOWS
|
||||
taosRealPath(dirname, temp, sizeof(temp));
|
||||
if (temp[1] == ':') pos += 3;
|
||||
#else
|
||||
strcpy(temp, dirname);
|
||||
#endif
|
||||
|
||||
if (taosDirExist(temp)) {
|
||||
chmod(temp, mode);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (strncmp(temp, TD_DIRSEP, 1) == 0) {
|
||||
pos += 1;
|
||||
} else if (strncmp(temp, "." TD_DIRSEP, 2) == 0) {
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
for (; *pos != '\0'; pos++) {
|
||||
if (*pos == TD_DIRSEP[0]) {
|
||||
*pos = '\0';
|
||||
#ifdef WINDOWS
|
||||
code = _mkdir(temp, mode);
|
||||
#else
|
||||
code = mkdir(temp, mode);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
*pos = TD_DIRSEP[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (*(pos - 1) != TD_DIRSEP[0]) {
|
||||
#ifdef WINDOWS
|
||||
code = _mkdir(temp, mode);
|
||||
#else
|
||||
code = mkdir(temp, mode);
|
||||
#endif
|
||||
if (code < 0 && errno != EEXIST) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (code < 0 && errno == EEXIST) {
|
||||
chmod(temp, mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
chmod(temp, mode);
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
||||
TdDirPtr pDir = taosOpenDir(dirname);
|
||||
if (pDir == NULL) return;
|
||||
|
|
Loading…
Reference in New Issue