From 68558b0116b713235611795b9c3e4c928da7acda Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 9 Dec 2024 08:16:14 +0000 Subject: [PATCH] enh: simple changes --- source/os/src/osDir.c | 17 ++++++----------- source/os/test/osDirTests.cpp | 3 +++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 189ccb8a8d..0485c8f6c4 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -340,19 +340,14 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { wordexp_t full_path = {0}; int32_t code = wordexp(dirname, &full_path, 0); - switch (code) { - case 0: - tstrncpy(outname, full_path.we_wordv[0], maxlen); - break; - case WRDE_NOSPACE: - wordfree(&full_path); - // FALL THROUGH - default: - return terrno = TSDB_CODE_INVALID_PARA; + if (code == 0 && full_path.we_wordv[0] != NULL) { + tstrncpy(outname, full_path.we_wordv[0], maxlen); + wordfree(&full_path); + return 0; } wordfree(&full_path); - return 0; + return terrno = TSDB_CODE_INVALID_PARA; } 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; - + totalSize += subSize; fullPath[0] = 0; } diff --git a/source/os/test/osDirTests.cpp b/source/os/test/osDirTests.cpp index eaf4781955..e6d64d61a2 100644 --- a/source/os/test/osDirTests.cpp +++ b/source/os/test/osDirTests.cpp @@ -268,6 +268,9 @@ TEST(osDirTests, taosExpandDir) { ret = taosExpandDir("/x123", fullpath, 1024); EXPECT_EQ(ret, 0); + ret = taosExpandDir("", fullpath, 1024); + EXPECT_NE(ret, 0); + char dir2[2048] = {0}; for (int32_t i = 0; i < 2047; ++i) { dir2[i] = '1';