New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: Remove DirIsWritable, GetUniquePath #28075
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, 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 |
fac69b3
to
9999d82
Compare
9999d82
to
fa4c289
Compare
fa4c289
to
fa5bcb6
Compare
Nice, Concept ACK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, ACK fa5bcb6
switch (util::LockDirectory(datadir, ".lock", probeOnly)) { | ||
case util::LockResult::ErrorWrite: | ||
return InitError(strprintf(_("Cannot write to data directory '%s'; check permissions."), fs::PathToString(datadir))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Or you can disable the settings feature.
@@ -149,7 +149,7 @@ bool BerkeleyEnvironment::Open(bilingual_str& err) | |||
|
|||
fs::path pathIn = fs::PathFromString(strPath); | |||
TryCreateDirectories(pathIn); | |||
if (!LockDirectory(pathIn, ".walletlock")) { | |||
if (util::LockDirectory(pathIn, ".walletlock") != util::LockResult::Success) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably improve the logging a bit here now that there is a diagnostic difference between a locking error and a lock write error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Concept ACK. |
fa5bcb6
to
fa61bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
src/test/util_tests.cpp
Outdated
@@ -1122,6 +1122,7 @@ static constexpr char ExitCommand = 'X'; | |||
ch = [&] { | |||
switch (util::LockDirectory(dirname, lockname)) { | |||
case util::LockResult::Success: return 1; | |||
case util::LockResult::ErrorWrite: return 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand what 2 means here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force pushed to rewrite this test completely to enum
erate all possible "return values" of TestOtherProcess
.
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.
fa61bfc
to
fa3da62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-ACK fa3da62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa3da62, I have reviewed the code and it looks OK.
GetUniquePath
is only used in tests and inDirIsWritable
. The check byDirIsWritable
is redundant with the check done inLockDirectory
.Fix the redundancy by removing everything, except
LockDirectory
.