From 12770cae888cfd8f07c6a19607d0fd54b977d16d Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 26 Sep 2020 22:01:07 +0300 Subject: [PATCH] mdbx-test: cleanup for without MDBX_NOSUBDIR case. Change-Id: I50d6640108ca229e4919ea96469152d2533f9cab --- .github/actions/spelling/expect.txt | 3 +++ test/main.cc | 15 +++++++++++++++ test/osal-unix.cc | 4 ++++ test/osal-windows.cc | 4 ++++ test/osal.h | 1 + 5 files changed, 27 insertions(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index e0863bad..b799ec73 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -367,6 +367,7 @@ EIDRM EINTR EINVAL EIO +EISDIR ejdb EKEYMISMATCH elbrus @@ -1315,6 +1316,7 @@ rej relpath relro RELWITHDEBINFO +removedirectory removefile Rescure resizable @@ -1333,6 +1335,7 @@ riverbankcomputing rkey rlock rlt +rmdir RMID rocksdb rolledback diff --git a/test/main.cc b/test/main.cc index 54088d6b..fd0bf21c 100644 --- a/test/main.cc +++ b/test/main.cc @@ -212,8 +212,23 @@ std::string thunk_param(const actor_config &config) { void cleanup() { log_trace(">> cleanup"); + const int is_dir = +#if defined(_WIN32) || defined(_WIN64) + ERROR_ACCESS_DENIED /* Windows API is mad */; +#else + EISDIR; +#endif for (const auto &db_path : global::databases) { int err = osal_removefile(db_path); + if (err == is_dir) { + err = osal_removefile(db_path + MDBX_LOCKNAME); + if (err == MDBX_SUCCESS || err == MDBX_ENOFILE) + err = osal_removefile(db_path + MDBX_DATANAME); + if (err == MDBX_SUCCESS || err == MDBX_ENOFILE) + err = osal_removedirectory(db_path); + } else if (err == MDBX_SUCCESS || err == MDBX_ENOFILE) + err = osal_removefile(db_path + MDBX_LOCK_SUFFIX); + if (err != MDBX_SUCCESS && err != MDBX_ENOFILE) failure_perror(db_path.c_str(), err); } diff --git a/test/osal-unix.cc b/test/osal-unix.cc index 0fa0624a..7e552e5c 100644 --- a/test/osal-unix.cc +++ b/test/osal-unix.cc @@ -535,4 +535,8 @@ int osal_removefile(const std::string &pathname) { return unlink(pathname.c_str()) ? errno : MDBX_SUCCESS; } +int osal_removedirectory(const std::string &pathname) { + return rmdir(pathname.c_str()) ? errno : MDBX_SUCCESS; +} + #endif /* !Windows */ diff --git a/test/osal-windows.cc b/test/osal-windows.cc index 29e5184e..ae31919e 100644 --- a/test/osal-windows.cc +++ b/test/osal-windows.cc @@ -456,4 +456,8 @@ int osal_removefile(const std::string &pathname) { return DeleteFileA(pathname.c_str()) ? MDBX_SUCCESS : GetLastError(); } +int osal_removedirectory(const std::string &pathname) { + return RemoveDirectoryA(pathname.c_str()) ? MDBX_SUCCESS : GetLastError(); +} + #endif /* Windows */ diff --git a/test/osal.h b/test/osal.h index e47450b9..129a9f1c 100644 --- a/test/osal.h +++ b/test/osal.h @@ -35,6 +35,7 @@ void osal_yield(void); bool osal_istty(int fd); std::string osal_tempdir(void); int osal_removefile(const std::string &pathname); +int osal_removedirectory(const std::string &pathname); #ifdef _MSC_VER #ifndef STDIN_FILENO