GetUniquePath is only used in tests and in DirIsWritable. The check by DirIsWritable is redundant with the check done in LockDirectory.
Fix the redundancy by removing everything, except LockDirectory.
GetUniquePath is only used in tests and in DirIsWritable. The check by DirIsWritable is redundant with the check done in LockDirectory.
Fix the redundancy by removing everything, except LockDirectory.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
For detailed information about the code coverage, see the test coverage report.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | TheCharlatan, hebasto |
| Concept ACK | theuni |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
make[2]: Entering directory '/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-arm-linux-gnueabihf/src'
/usr/bin/ccache arm-linux-gnueabihf-g++ -std=c++17 -DHAVE_CONFIG_H -I. -I../src/config -fmacro-prefix-map=/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-arm-linux-gnueabihf=. -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -DHAVE_BUILD_INFO -D_FILE_OFFSET_BITS=64 -DPROVIDE_FUZZ_MAIN_FUNCTION -I. -I./minisketch/include -I./secp256k1/include -I./univalue/include -I./leveldb/include -isystem /tmp/cirrus-ci-build/depends/arm-linux-gnueabihf/include -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_NO_CXX98_FUNCTION_BASE -isystem /tmp/cirrus-ci-build/depends/arm-linux-gnueabihf/include -pthread -I/tmp/cirrus-ci-build/depends/arm-linux-gnueabihf/include -I/tmp/cirrus-ci-build/depends/arm-linux-gnueabihf/include/ -fdebug-prefix-map=/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-arm-linux-gnueabihf=. -fstack-reuse=none -Wstack-protector -fstack-protector-all -fstack-clash-protection -Werror -fno-extended-identifiers -fvisibility=hidden -fPIE -pipe -std=c++17 -O2 -Wno-psabi -c -o libbitcoin_node_a-init.o `test -f 'init.cpp' || echo './'`init.cpp
init.cpp: In function ‘bool LockDataDirectory(bool)’:
init.cpp:1021:1: error: control reaches end of non-void function [-Werror=return-type]
1021 | }
| ^
cc1plus: all warnings being treated as errors
make[2]: *** [Makefile:10093: libbitcoin_node_a-init.o] Error 1
Nice, Concept ACK.
1011 | @@ -1012,10 +1012,9 @@ static bool LockDataDirectory(bool probeOnly) 1012 | { 1013 | // Make sure only a single Bitcoin process is using the data directory. 1014 | const fs::path& datadir = gArgs.GetDataDirNet(); 1015 | - if (!DirIsWritable(datadir)) { 1016 | - return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir))); 1017 | - } 1018 | switch (util::LockDirectory(datadir, ".lock", probeOnly)) { 1019 | + case util::LockResult::ErrorWrite: 1020 | + return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir)));
While testing I noticed that the settings file in the datadir is already interacted with before we do this check. So I think the only way to trigger this is if the lock file has bad permissions.
Correct. Or you can disable the settings feature.
148 | @@ -149,7 +149,7 @@ bool BerkeleyEnvironment::Open(bilingual_str& err) 149 | 150 | fs::path pathIn = fs::PathFromString(strPath); 151 | TryCreateDirectories(pathIn); 152 | - if (!LockDirectory(pathIn, ".walletlock")) { 153 | + if (util::LockDirectory(pathIn, ".walletlock") != util::LockResult::Success) {
Could probably improve the logging a bit here now that there is a diagnostic difference between a locking error and a lock write error.
I don't think there is a difference, at least when the wallets are placed inside the datadir. Maybe for wallets outside the datadir this is different? In any case, it seems unrelated, as this pull is not changing any behavior.
Nice, ACK fa5bcb6dafe376f81a669bf9324eedecf3feeb8b
Concept ACK.
1121 | @@ -1122,6 +1122,7 @@ static constexpr char ExitCommand = 'X'; 1122 | ch = [&] { 1123 | switch (util::LockDirectory(dirname, lockname)) { 1124 | case util::LockResult::Success: return 1; 1125 | + case util::LockResult::ErrorWrite: return 2;
Can you help me understand what 2 means here?
This piece of code translates the return value of the LockDirectory function to a value of type char, so that it can be written as one byte in the next line. Previously, it would assign the boolean return value to char, so I picked 1 for true/Success and 0 for false/ErrorLock.
Now that the LockResult enum can hold more than a binary result, I am mapping the new return value ErrorWrite to a char value of 2.
However, that value is never read and the code is never hit, so it can be anything.
Happy to change to anything else, if you have suggestions.
Force pushed to rewrite this test completely to enumerate all possible "return values" of TestOtherProcess.
Concept ACK.
This makes it easier to add more Error cases in the future. Also, add
missing util namespace.
This allows the caller to remove a call to DirIsWritable(), which did a
similar check. Users should not notice any different behavior.
Re-ACK fa3da629a1aebcb4500803d7417feed8e34285b0
ACK fa3da629a1aebcb4500803d7417feed8e34285b0, I have reviewed the code and it looks OK.