From 4381931ed45e2ba491d7bc5d16a2542749839bea Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 26 May 2022 12:13:06 +0800 Subject: [PATCH] fix: mkdir with newly added tiered storage --- src/os/inc/osDir.h | 1 + src/os/src/detail/osDir.c | 31 +++++++++++++++++++++++++++++-- src/tsdb/inc/tsdbFile.h | 9 ++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/os/inc/osDir.h b/src/os/inc/osDir.h index 7afe126451..079f2aca64 100644 --- a/src/os/inc/osDir.h +++ b/src/os/inc/osDir.h @@ -22,6 +22,7 @@ extern "C" { void taosRemoveDir(char *rootDir); bool taosDirExist(const char* dirname); +int32_t taosMkdirP(const char *pathname); int32_t taosMkDir(const char *pathname, mode_t mode); void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays); int32_t taosRename(char *oldName, char *newName); diff --git a/src/os/src/detail/osDir.c b/src/os/src/detail/osDir.c index c467c64872..61daf913a3 100644 --- a/src/os/src/detail/osDir.c +++ b/src/os/src/detail/osDir.c @@ -49,8 +49,35 @@ bool taosDirExist(const char* dirname) { return access(dirname, F_OK) == 0; } -int taosMkDir(const char *path, mode_t mode) { - int code = mkdir(path, 0755); +int32_t taosMkdirP(const char *dir) { + char tmp[256]; + char *p = NULL; + size_t len; + int i; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + for (i = len - 1; i > 0; --i) + if (tmp[i] == '/') { + tmp[i] = 0; + break; + } + + for (p = tmp + 1; *p; p++) + if (*p == '/') { + *p = 0; + if (mkdir(tmp, S_IRWXU) && errno != EEXIST) + return -1; + *p = '/'; + } + if (mkdir(tmp, S_IRWXU) && errno != EEXIST) + return -1; + + return 0; +} + +int32_t taosMkDir(const char *path, mode_t mode) { + int code = mkdir(path, mode); if (code < 0 && errno == EEXIST) code = 0; return code; } diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index 6d1e0cf246..6872385a8a 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -288,8 +288,11 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { if (tfscopy(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + int32_t ret = taosMkdirP(TSDB_FILE_FULL_NAME(pDest)); + if (ret < 0 || tfscopy(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } } tsdbSetDFileInfo(pDest, TSDB_FILE_INFO(pSrc)); @@ -401,4 +404,4 @@ static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) { return true; } -#endif /* _TS_TSDB_FILE_H_ */ \ No newline at end of file +#endif /* _TS_TSDB_FILE_H_ */ -- GitLab