From a2317486878a898c48f33b16c60c2a2460e63d66 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 9 Dec 2024 09:06:24 +0000 Subject: [PATCH] enh: minor changes --- source/os/src/osDir.c | 18 +++++++++++++----- source/os/test/osDirTests.cpp | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 0485c8f6c4..410f9da623 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -336,18 +336,26 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { OS_PARAM_CHECK(dirname); OS_PARAM_CHECK(outname); - outname[0] = 0; + if (dirname[0] == 0) return 0; wordexp_t full_path = {0}; int32_t code = wordexp(dirname, &full_path, 0); - if (code == 0 && full_path.we_wordv[0] != NULL) { + switch (code) { + case 0: + break; + case WRDE_NOSPACE: + wordfree(&full_path); + // FALL THROUGH + default: + return terrno = TSDB_CODE_INVALID_PARA; + } + + if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { tstrncpy(outname, full_path.we_wordv[0], maxlen); - wordfree(&full_path); - return 0; } wordfree(&full_path); - return terrno = TSDB_CODE_INVALID_PARA; + return 0; } int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { diff --git a/source/os/test/osDirTests.cpp b/source/os/test/osDirTests.cpp index e6d64d61a2..1d649addd2 100644 --- a/source/os/test/osDirTests.cpp +++ b/source/os/test/osDirTests.cpp @@ -269,7 +269,7 @@ TEST(osDirTests, taosExpandDir) { EXPECT_EQ(ret, 0); ret = taosExpandDir("", fullpath, 1024); - EXPECT_NE(ret, 0); + EXPECT_EQ(ret, 0); char dir2[2048] = {0}; for (int32_t i = 0; i < 2047; ++i) {