From 89ff78d99c615c6bbd7129f3f5802b661e17274d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 16 Aug 2023 17:32:08 +0800 Subject: [PATCH 1/7] fix: fix non-root users cannot create log files even if they have write permission of the directory --- source/os/src/osDir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 3d63da7ba3..7e4058d508 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -206,7 +206,11 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) { #endif if (taosDirExist(temp)) { - return chmod(temp, mode); + if (taosCheckAccessFile(temp, TD_FILE_ACCESS_WRITE_OK)) { + return code; + } else { + return chmod(temp, mode); + } } if (strncmp(temp, TD_DIRSEP, 1) == 0) { From 962a0cd403ea08223dc10fefcb8f3a712296be0d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 23 Aug 2023 23:34:02 +0800 Subject: [PATCH 2/7] fix --- include/os/osDir.h | 2 +- source/common/src/tglobal.c | 2 +- source/libs/stream/src/streamMeta.c | 4 ++-- source/libs/stream/src/streamState.c | 2 +- source/libs/tdb/src/db/tdbDb.c | 2 +- source/os/src/osDir.c | 7 +++++-- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/os/osDir.h b/include/os/osDir.h index 55c7a15764..2542f9830f 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -83,7 +83,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); +int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile); 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/source/common/src/tglobal.c b/source/common/src/tglobal.c index 5eeece9890..3edb70e63f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1434,7 +1434,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false); - if (taosMulModeMkDir(tsLogDir, 0777) != 0) { + if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); printf("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index fe455c0190..61da055b25 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -52,7 +52,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "checkpoints"); - code = taosMulModeMkDir(streamPath, 0755); + code = taosMulModeMkDir(streamPath, 0755, false); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; @@ -90,7 +90,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "state"); - code = taosMulModeMkDir(streamPath, 0755); + code = taosMulModeMkDir(streamPath, 0755, false); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 5b42be182c..8694e5cf4c 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -169,7 +169,7 @@ SStreamState* streamStateOpen(char* path, void* pTask, bool specPath, int32_t sz sscanf(cfg, "%d\n%d\n", &szPage, &pages); } } else { - int32_t code = taosMulModeMkDir(statePath, 0755); + int32_t code = taosMulModeMkDir(statePath, 0755, false); if (code == 0) { pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE); sprintf(cfg, "%d\n%d\n", szPage, pages); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 4f595d8d4a..81b306e65d 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -62,7 +62,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i } memset(pDb->pgrHash, 0, tsize); - ret = taosMulModeMkDir(dbname, 0755); + ret = taosMulModeMkDir(dbname, 0755, false); if (ret < 0) { return -1; } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 7e4058d508..e9f8c7f7e6 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) { return code; } -int32_t taosMulModeMkDir(const char *dirname, int mode) { +int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; char temp[TDDIRMAXLEN]; char *pos = temp; @@ -206,7 +206,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) { #endif if (taosDirExist(temp)) { - if (taosCheckAccessFile(temp, TD_FILE_ACCESS_WRITE_OK)) { + if (createLogFile) { + if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + code = -1; + } return code; } else { return chmod(temp, mode); From 13d2d72bb61a0d504cb7738241dc802a1597275d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 24 Aug 2023 14:56:14 +0800 Subject: [PATCH 3/7] add seperate function for createLogs --- include/os/osDir.h | 3 +- source/common/src/tglobal.c | 2 +- source/libs/stream/src/streamMeta.c | 4 +- source/libs/stream/src/streamState.c | 2 +- source/libs/tdb/src/db/tdbDb.c | 2 +- source/os/src/osDir.c | 71 +++++++++++++++++++++++++--- 6 files changed, 71 insertions(+), 13 deletions(-) diff --git a/include/os/osDir.h b/include/os/osDir.h index 2542f9830f..e722adcdcc 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -83,7 +83,8 @@ 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, bool createLogFile); +int32_t taosMulModeMkDir(const char *dirname, int mode); +int32_t taosMulModeMkLogDir(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/source/common/src/tglobal.c b/source/common/src/tglobal.c index 3edb70e63f..611b88bc9d 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1434,7 +1434,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false); - if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) { + if (taosMulModeMkLogDir(tsLogDir, 0777) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); printf("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 61da055b25..fe455c0190 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -52,7 +52,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "checkpoints"); - code = taosMulModeMkDir(streamPath, 0755, false); + code = taosMulModeMkDir(streamPath, 0755); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; @@ -90,7 +90,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "state"); - code = taosMulModeMkDir(streamPath, 0755, false); + code = taosMulModeMkDir(streamPath, 0755); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 8694e5cf4c..5b42be182c 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -169,7 +169,7 @@ SStreamState* streamStateOpen(char* path, void* pTask, bool specPath, int32_t sz sscanf(cfg, "%d\n%d\n", &szPage, &pages); } } else { - int32_t code = taosMulModeMkDir(statePath, 0755, false); + int32_t code = taosMulModeMkDir(statePath, 0755); if (code == 0) { pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE); sprintf(cfg, "%d\n%d\n", szPage, pages); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 81b306e65d..4f595d8d4a 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -62,7 +62,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i } memset(pDb->pgrHash, 0, tsize); - ret = taosMulModeMkDir(dbname, 0755, false); + ret = taosMulModeMkDir(dbname, 0755); if (ret < 0) { return -1; } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index e9f8c7f7e6..dff0cf9886 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) { return code; } -int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { +int32_t taosMulModeMkDir(const char *dirname, int mode) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; char temp[TDDIRMAXLEN]; char *pos = temp; @@ -206,16 +206,73 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { #endif if (taosDirExist(temp)) { - if (createLogFile) { - if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { - code = -1; + return chmod(temp, mode); + } + + 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); +#elif defined(DARWIN) + code = mkdir(dirname, 0777); +#else + code = mkdir(temp, mode); +#endif + if (code < 0 && errno != EEXIST) { + // terrno = TAOS_SYSTEM_ERROR(errno); + return code; } - return code; - } else { - return chmod(temp, mode); + *pos = TD_DIRSEP[0]; } } + if (*(pos - 1) != TD_DIRSEP[0]) { +#ifdef WINDOWS + code = _mkdir(temp, mode); +#elif defined(DARWIN) + code = mkdir(dirname, 0777); +#else + code = mkdir(temp, mode); +#endif + if (code < 0 && errno != EEXIST) { + // terrno = TAOS_SYSTEM_ERROR(errno); + return code; + } + } + + if (code < 0 && errno == EEXIST) { + return chmod(temp, mode); + } + + return chmod(temp, mode); +} + +int32_t taosMulModeMkLogDir(const char *dirname, int mode) { + if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; + char temp[TDDIRMAXLEN]; + 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)) { + if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + code = -1; + } + return code; + } + if (strncmp(temp, TD_DIRSEP, 1) == 0) { pos += 1; } else if (strncmp(temp, "." TD_DIRSEP, 2) == 0) { From af130cc92f6ace15646fb36b45a5df650a8aebc3 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 25 Aug 2023 09:55:50 +0800 Subject: [PATCH 4/7] Revert "add seperate function for createLogs" This reverts commit 13d2d72bb61a0d504cb7738241dc802a1597275d. --- include/os/osDir.h | 3 +- source/common/src/tglobal.c | 2 +- source/libs/stream/src/streamMeta.c | 4 +- source/libs/stream/src/streamState.c | 2 +- source/libs/tdb/src/db/tdbDb.c | 2 +- source/os/src/osDir.c | 69 +++------------------------- 6 files changed, 12 insertions(+), 70 deletions(-) diff --git a/include/os/osDir.h b/include/os/osDir.h index e722adcdcc..2542f9830f 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -83,8 +83,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); -int32_t taosMulModeMkLogDir(const char *dirname, int mode); +int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile); 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/source/common/src/tglobal.c b/source/common/src/tglobal.c index 611b88bc9d..3edb70e63f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1434,7 +1434,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false); - if (taosMulModeMkLogDir(tsLogDir, 0777) != 0) { + if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); printf("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index fe455c0190..61da055b25 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -52,7 +52,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "checkpoints"); - code = taosMulModeMkDir(streamPath, 0755); + code = taosMulModeMkDir(streamPath, 0755, false); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; @@ -90,7 +90,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF memset(streamPath, 0, len); sprintf(streamPath, "%s/%s", pMeta->path, "state"); - code = taosMulModeMkDir(streamPath, 0755); + code = taosMulModeMkDir(streamPath, 0755, false); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(code); goto _err; diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 5b42be182c..8694e5cf4c 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -169,7 +169,7 @@ SStreamState* streamStateOpen(char* path, void* pTask, bool specPath, int32_t sz sscanf(cfg, "%d\n%d\n", &szPage, &pages); } } else { - int32_t code = taosMulModeMkDir(statePath, 0755); + int32_t code = taosMulModeMkDir(statePath, 0755, false); if (code == 0) { pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE); sprintf(cfg, "%d\n%d\n", szPage, pages); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 4f595d8d4a..81b306e65d 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -62,7 +62,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i } memset(pDb->pgrHash, 0, tsize); - ret = taosMulModeMkDir(dbname, 0755); + ret = taosMulModeMkDir(dbname, 0755, false); if (ret < 0) { return -1; } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index dff0cf9886..e9f8c7f7e6 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) { return code; } -int32_t taosMulModeMkDir(const char *dirname, int mode) { +int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; char temp[TDDIRMAXLEN]; char *pos = temp; @@ -206,73 +206,16 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) { #endif if (taosDirExist(temp)) { - return chmod(temp, mode); - } - - 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); -#elif defined(DARWIN) - code = mkdir(dirname, 0777); -#else - code = mkdir(temp, mode); -#endif - if (code < 0 && errno != EEXIST) { - // terrno = TAOS_SYSTEM_ERROR(errno); - return code; + if (createLogFile) { + if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + code = -1; } - *pos = TD_DIRSEP[0]; - } - } - - if (*(pos - 1) != TD_DIRSEP[0]) { -#ifdef WINDOWS - code = _mkdir(temp, mode); -#elif defined(DARWIN) - code = mkdir(dirname, 0777); -#else - code = mkdir(temp, mode); -#endif - if (code < 0 && errno != EEXIST) { - // terrno = TAOS_SYSTEM_ERROR(errno); return code; + } else { + return chmod(temp, mode); } } - if (code < 0 && errno == EEXIST) { - return chmod(temp, mode); - } - - return chmod(temp, mode); -} - -int32_t taosMulModeMkLogDir(const char *dirname, int mode) { - if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; - char temp[TDDIRMAXLEN]; - 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)) { - if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { - code = -1; - } - return code; - } - if (strncmp(temp, TD_DIRSEP, 1) == 0) { pos += 1; } else if (strncmp(temp, "." TD_DIRSEP, 2) == 0) { From c8c30e0a00c508faf6a8428846516386124b9f47 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 25 Aug 2023 10:15:52 +0800 Subject: [PATCH 5/7] fix --- include/os/osDir.h | 2 +- source/os/src/osDir.c | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/os/osDir.h b/include/os/osDir.h index 2542f9830f..533ac8e4a4 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -83,7 +83,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, bool createLogFile); +int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess); 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/source/os/src/osDir.c b/source/os/src/osDir.c index e9f8c7f7e6..d0fb7ee919 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) { return code; } -int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { +int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; char temp[TDDIRMAXLEN]; char *pos = temp; @@ -206,14 +206,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool createLogFile) { #endif if (taosDirExist(temp)) { - if (createLogFile) { - if (!taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { - code = -1; - } + if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { return code; - } else { - return chmod(temp, mode); } + return chmod(temp, mode); } if (strncmp(temp, TD_DIRSEP, 1) == 0) { From c60ac2b8ae62f0a33bf1e71536ed0045d78f5e63 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 28 Aug 2023 09:45:50 +0800 Subject: [PATCH 6/7] fix --- source/os/src/osDir.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index d0fb7ee919..df4d03c118 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -207,7 +207,7 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { if (taosDirExist(temp)) { if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { - return code; + return 0; } return chmod(temp, mode); } @@ -251,9 +251,15 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { } if (code < 0 && errno == EEXIST) { + if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + return 0; + } return chmod(temp, mode); } + if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + return 0; + } return chmod(temp, mode); } From 2f46b2eefd35efa5a927acb4d742d7d2bda09e1a Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 28 Aug 2023 10:10:16 +0800 Subject: [PATCH 7/7] fix --- source/os/src/osDir.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index df4d03c118..6e52c4ed27 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -257,9 +257,6 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { return chmod(temp, mode); } - if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { - return 0; - } return chmod(temp, mode); }