From 1673cf934b0871a6dd3b552a80913a5737fa3f61 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:02:48 -0500 Subject: Add Path::removeNonEmpty() to remove non-empty dir (#4984) We've implemented a function in slang-record-replay unit test to remove the non-empty directory, now move this function into slang `Path` namespace to make this function as an utility. Close issue #4916 --- tools/slang-unit-test/unit-test-record-replay.cpp | 59 ++--------------------- 1 file changed, 5 insertions(+), 54 deletions(-) (limited to 'tools') diff --git a/tools/slang-unit-test/unit-test-record-replay.cpp b/tools/slang-unit-test/unit-test-record-replay.cpp index d775e1421..33bbab0c3 100644 --- a/tools/slang-unit-test/unit-test-record-replay.cpp +++ b/tools/slang-unit-test/unit-test-record-replay.cpp @@ -9,13 +9,6 @@ #include "tools/unit-test/slang-unit-test.h" -#ifdef _WIN32 -#include -#include -#else -#include -#endif - #include #include @@ -355,55 +348,13 @@ static SlangResult resultCompare(List const& expectHashes, Listmessage(TestMessageType::TestFailure, msgBuilder.toString().getBuffer()); - return SLANG_FAIL; - } -#else - auto unlink_cb = [](const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) -> int - { - int rv = ::remove(fpath); - if (rv) - { - perror(fpath); - } - return rv; - }; - // https://linux.die.net/man/3/nftw - int ret = nftw("slang-record", unlink_cb, 64, FTW_DEPTH | FTW_PHYS); - if (ret) + SlangResult res = Path::removeNonEmpty("slang-record"); + if (SLANG_FAILED(res)) { - msgBuilder << "fail to remove 'slang-record' dir, error: " << ret << ", " << strerror(errno) << "\n"; - getTestReporter()->message(TestMessageType::TestFailure, msgBuilder.toString().getBuffer()); - return SLANG_FAIL; + getTestReporter()->message(TestMessageType::TestFailure, "Failed to remove 'slang-record' directory\n"); } -#endif - return SLANG_OK; + return res; } static SlangResult runTest(UnitTestContext* context, const char* testName) @@ -427,7 +378,7 @@ static SlangResult runTest(UnitTestContext* context, const char* testName) } error: - cleanupRecordFiles(); + res = cleanupRecordFiles(); return res; } -- cgit v1.2.3