Merge pull request #16568 from taosdata/fix/ZhiqiangWang/TD-18410-chmod-log-dir-mode
os: chmod log dir mode
This commit is contained in:
commit
752104bf7a
|
@ -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);
|
||||
|
|
|
@ -45,6 +45,7 @@ mkdir -p ${pkg_dir}${install_home_path}/include
|
|||
mkdir -p ${pkg_dir}${install_home_path}/script
|
||||
|
||||
cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg
|
||||
cp ${compile_dir}/../packaging/cfg/taosd.service ${pkg_dir}${install_home_path}/cfg
|
||||
if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then
|
||||
cp ${compile_dir}/test/cfg/taosadapter.toml ${pkg_dir}${install_home_path}/cfg || :
|
||||
fi
|
||||
|
|
|
@ -1133,7 +1133,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