enh: simple changes

This commit is contained in:
Shengliang Guan 2024-12-09 08:16:14 +00:00
parent 5028191796
commit 68558b0116
2 changed files with 9 additions and 11 deletions

View File

@ -340,19 +340,14 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path = {0}; wordexp_t full_path = {0};
int32_t code = wordexp(dirname, &full_path, 0); int32_t code = wordexp(dirname, &full_path, 0);
switch (code) { if (code == 0 && full_path.we_wordv[0] != NULL) {
case 0: tstrncpy(outname, full_path.we_wordv[0], maxlen);
tstrncpy(outname, full_path.we_wordv[0], maxlen); wordfree(&full_path);
break; return 0;
case WRDE_NOSPACE:
wordfree(&full_path);
// FALL THROUGH
default:
return terrno = TSDB_CODE_INVALID_PARA;
} }
wordfree(&full_path); wordfree(&full_path);
return 0; return terrno = TSDB_CODE_INVALID_PARA;
} }
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
@ -607,7 +602,7 @@ int32_t taosGetDirSize(const char *path, int64_t *size) {
} }
if (code != 0) goto _OVER; if (code != 0) goto _OVER;
totalSize += subSize; totalSize += subSize;
fullPath[0] = 0; fullPath[0] = 0;
} }

View File

@ -268,6 +268,9 @@ TEST(osDirTests, taosExpandDir) {
ret = taosExpandDir("/x123", fullpath, 1024); ret = taosExpandDir("/x123", fullpath, 1024);
EXPECT_EQ(ret, 0); EXPECT_EQ(ret, 0);
ret = taosExpandDir("", fullpath, 1024);
EXPECT_NE(ret, 0);
char dir2[2048] = {0}; char dir2[2048] = {0};
for (int32_t i = 0; i < 2047; ++i) { for (int32_t i = 0; i < 2047; ++i) {
dir2[i] = '1'; dir2[i] = '1';