提交 4381931e 编写于 作者: M Minglei Jin

fix: mkdir with newly added tiered storage

上级 586201e1
......@@ -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);
......
......@@ -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;
}
......
......@@ -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_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册