Skip to content

Commit 280ced3

Browse files
ken2812221furszy
authored andcommitted
utils: Fix broken Windows filelock
1 parent be89860 commit 280ced3

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/fs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef WIN32
99
#include <fcntl.h>
1010
#else
11+
#define NOMINMAX
1112
#include <codecvt>
1213
#include <windows.h>
1314
#endif
@@ -95,7 +96,7 @@ bool FileLock::TryLock()
9596
return false;
9697
}
9798
_OVERLAPPED overlapped = {0};
98-
if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 0, &overlapped)) {
99+
if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, std::numeric_limits<DWORD>::max(), std::numeric_limits<DWORD>::max(), &overlapped)) {
99100
reason = GetErrorReason();
100101
return false;
101102
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Check that it's not possible to start a second pivxd instance using the same datadir or wallet."""
6+
import os
7+
8+
from test_framework.test_framework import PivxTestFramework
9+
from test_framework.test_node import ErrorMatch
10+
11+
class FilelockTest(PivxTestFramework):
12+
def set_test_params(self):
13+
self.setup_clean_chain = True
14+
self.num_nodes = 2
15+
16+
def setup_network(self):
17+
self.add_nodes(self.num_nodes, extra_args=None)
18+
self.nodes[0].start([])
19+
self.nodes[0].wait_for_rpc_connection()
20+
21+
def is_wallet_compiled(self):
22+
return True
23+
24+
def run_test(self):
25+
datadir = os.path.join(self.nodes[0].datadir, 'regtest')
26+
self.log.info("Using datadir {}".format(datadir))
27+
28+
self.log.info("Check that we can't start a second pivxd instance using the same datadir")
29+
expected_msg = "Error: Cannot obtain a lock on data directory {}. PIVX Core is probably already running.".format(datadir)
30+
self.nodes[1].assert_start_raises_init_error(extra_args=['-datadir={}'.format(self.nodes[0].datadir), '-noserver'], expected_msg=expected_msg)
31+
32+
if self.is_wallet_compiled():
33+
wallet_dir = os.path.join(datadir, 'wallets')
34+
self.log.info("Check that we can't start a second pivxd instance using the same wallet")
35+
expected_msg = "Error: Error initializing wallet database environment"
36+
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
37+
38+
if __name__ == '__main__':
39+
FilelockTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
'mining_v5_upgrade.py', # ~ 48 sec
128128
'p2p_mempool.py', # ~ 46 sec
129129
'rpc_named_arguments.py', # ~ 45 sec
130+
'feature_filelock.py',
130131
'feature_help.py', # ~ 30 sec
131132

132133
# Don't append tests at the end to avoid merge conflicts

0 commit comments

Comments
 (0)