未验证 提交 fb790622 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #13013 from taosdata/fix/TS-1458

fix: mkdir with newly added tiered storage
...@@ -22,6 +22,7 @@ extern "C" { ...@@ -22,6 +22,7 @@ extern "C" {
void taosRemoveDir(char *rootDir); void taosRemoveDir(char *rootDir);
bool taosDirExist(const char* dirname); bool taosDirExist(const char* dirname);
int32_t taosMkdirP(const char *pathname);
int32_t taosMkDir(const char *pathname, mode_t mode); int32_t taosMkDir(const char *pathname, mode_t mode);
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays); void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
int32_t taosRename(char *oldName, char *newName); int32_t taosRename(char *oldName, char *newName);
......
...@@ -49,8 +49,35 @@ bool taosDirExist(const char* dirname) { ...@@ -49,8 +49,35 @@ bool taosDirExist(const char* dirname) {
return access(dirname, F_OK) == 0; return access(dirname, F_OK) == 0;
} }
int taosMkDir(const char *path, mode_t mode) { int32_t taosMkdirP(const char *dir) {
int code = mkdir(path, 0755); 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; if (code < 0 && errno == EEXIST) code = 0;
return code; return code;
} }
......
...@@ -288,9 +288,12 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby ...@@ -288,9 +288,12 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby
static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) {
if (tfscopy(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { if (tfscopy(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) {
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); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
}
tsdbSetDFileInfo(pDest, TSDB_FILE_INFO(pSrc)); tsdbSetDFileInfo(pDest, TSDB_FILE_INFO(pSrc));
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册