upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/rpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc.cpp')
-rw-r--r--src/rpc.cpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp
index cebc349..e4939b3 100644
--- a/src/rpc.cpp
+++ b/src/rpc.cpp
@@ -32,6 +32,7 @@
32#include <arpa/inet.h> 32#include <arpa/inet.h>
33#include <unistd.h> 33#include <unistd.h>
34#include <fcntl.h> 34#include <fcntl.h>
35#include <dirent.h>
35#else 36#else
36#include <io.h> 37#include <io.h>
37#endif 38#endif
@@ -2775,6 +2776,39 @@ static bool PayoutTestReadFile(const std::string& path, std::string& out)
2775 return true; 2776 return true;
2776} 2777}
2777 2778
2779// Delete the scratch data directory and everything in it. A sweep and not a
2780// list of known names: LogPrint binds debug.log to whatever GetAppDir() is
2781// when it first fires, so the test's own log lands in here too, and a
2782// directory left behind in src/ after `make tests` is litter.
2783static void PayoutTestRemoveDir(const std::string& dir)
2784{
2785#ifdef _WIN32
2786 WIN32_FIND_DATAA findData;
2787 HANDLE hFind = FindFirstFileA((dir + "\\*").c_str(), &findData);
2788 if (hFind != INVALID_HANDLE_VALUE) {
2789 do {
2790 std::string name = findData.cFileName;
2791 if (name == "." || name == "..") continue;
2792 DeleteFileA((dir + "\\" + name).c_str());
2793 } while (FindNextFileA(hFind, &findData));
2794 FindClose(hFind);
2795 }
2796 RemoveDirectoryA(dir.c_str());
2797#else
2798 DIR* d = opendir(dir.c_str());
2799 if (d) {
2800 struct dirent* ent;
2801 while ((ent = readdir(d)) != NULL) {
2802 std::string name = ent->d_name;
2803 if (name == "." || name == "..") continue;
2804 unlink((dir + "/" + name).c_str());
2805 }
2806 closedir(d);
2807 }
2808 rmdir(dir.c_str());
2809#endif
2810}
2811
2778static bool PayoutTestWriteFile(const std::string& path, const std::string& data) 2812static bool PayoutTestWriteFile(const std::string& path, const std::string& data)
2779{ 2813{
2780 FILE* f = fopen(path.c_str(), "w"); 2814 FILE* f = fopen(path.c_str(), "w");
@@ -2869,9 +2903,14 @@ int RunPayoutLedgerSelfTest()
2869 // Scratch data directory in the current working directory. GetAppDir() 2903 // Scratch data directory in the current working directory. GetAppDir()
2870 // follows strSetDataDir, so this is what PayoutFilePath() and 2904 // follows strSetDataDir, so this is what PayoutFilePath() and
2871 // PayingFilePath() resolve against for the rest of the test. 2905 // PayingFilePath() resolve against for the rest of the test.
2872 std::string dir = strprintf("payout_selftest_%d", (int)GetTime());
2873#ifdef _WIN32 2906#ifdef _WIN32
2874 _mkdir(dir.c_str()); 2907 unsigned long pid = (unsigned long)GetCurrentProcessId();
2908#else
2909 unsigned long pid = (unsigned long)getpid();
2910#endif
2911 std::string dir = strprintf("payout_selftest_%d_%lu", (int)GetTime(), pid);
2912#ifdef _WIN32
2913 CreateDirectoryA(dir.c_str(), NULL);
2875#else 2914#else
2876 mkdir(dir.c_str(), 0700); 2915 mkdir(dir.c_str(), 0700);
2877#endif 2916#endif
@@ -3400,17 +3439,7 @@ int RunPayoutLedgerSelfTest()
3400 PayoutTestResetState(); 3439 PayoutTestResetState();
3401 CRITICAL_BLOCK(cs_mapWallet) 3440 CRITICAL_BLOCK(cs_mapWallet)
3402 mapWallet.clear(); 3441 mapWallet.clear();
3403 remove(ledgerPath.c_str()); 3442 PayoutTestRemoveDir(dir);
3404 remove((ledgerPath + ".tmp").c_str());
3405 remove(payingPath.c_str());
3406 remove((payingPath + ".tmp").c_str());
3407 remove((dir + "/pool_status.json").c_str());
3408 remove((dir + "/pool_rounds.json").c_str());
3409#ifdef _WIN32
3410 _rmdir(dir.c_str());
3411#else
3412 rmdir(dir.c_str());
3413#endif
3414 strSetDataDir = savedDataDir; 3443 strSetDataDir = savedDataDir;
3415 nBestHeight = savedBestHeight; 3444 nBestHeight = savedBestHeight;
3416 3445