diff --git a/include/os/osDir.h b/include/os/osDir.h index 9019d4f80240b2335824cb5626488bf4d0957f06..95b1a6ee1d00ab18e31522063102ff0ec9a2bab8 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -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); diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index 3db9005f95a3027c42dd05b9f28d448ade5852cb..94a24a41487e8d7b82571bcc524392e4335d7fae 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -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 diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 47110237dd1c7803ec8c3641551f926dbcb3d7a0..908f7c014e9e1088a8fa3f7243aa545f56acc0bc 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -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; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 30aaa01dae0bf26bb930271f056d77226e808a4d..3dfb1458ad2fc802af761f68a4fe4407098fff25 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -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;