提交 25a86df8 编写于 作者: M Minglei Jin

fix: mkdir recursively with wal directory

上级 b1b294ed
...@@ -22,7 +22,7 @@ extern "C" { ...@@ -22,7 +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 taosMkdirP(const char *pathname, int keepBase);
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,7 +49,7 @@ bool taosDirExist(const char* dirname) { ...@@ -49,7 +49,7 @@ bool taosDirExist(const char* dirname) {
return access(dirname, F_OK) == 0; return access(dirname, F_OK) == 0;
} }
int32_t taosMkdirP(const char *dir) { int32_t taosMkdirP(const char *dir, int keepLast) {
char tmp[256]; char tmp[256];
char *p = NULL; char *p = NULL;
size_t len; size_t len;
...@@ -57,11 +57,13 @@ int32_t taosMkdirP(const char *dir) { ...@@ -57,11 +57,13 @@ int32_t taosMkdirP(const char *dir) {
snprintf(tmp, sizeof(tmp),"%s",dir); snprintf(tmp, sizeof(tmp),"%s",dir);
len = strlen(tmp); len = strlen(tmp);
for (i = len - 1; i > 0; --i) if (!keepLast) {
if (tmp[i] == '/') { for (i = len - 1; i > 0; --i)
tmp[i] = 0; if (tmp[i] == '/') {
break; tmp[i] = 0;
} break;
}
}
for (p = tmp + 1; *p; p++) for (p = tmp + 1; *p; p++)
if (*p == '/') { if (*p == '/') {
......
...@@ -288,7 +288,7 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby ...@@ -288,7 +288,7 @@ 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)); int32_t ret = taosMkdirP(TSDB_FILE_FULL_NAME(pDest), 0);
if (ret < 0 || tfscopy(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { 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;
......
...@@ -139,7 +139,7 @@ void walClose(void *handle) { ...@@ -139,7 +139,7 @@ void walClose(void *handle) {
} }
static int32_t walInitObj(SWal *pWal) { static int32_t walInitObj(SWal *pWal) {
if (taosMkDir(pWal->path, 0755) != 0) { if (taosMkdirP(pWal->path, 1) != 0) {
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno)); wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno));
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册