Skip to content
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

Merged
merged 3 commits into from Dec 13, 2023

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jul 14, 2023

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 14, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

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.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28710 (Remove the legacy wallet and BDB dependency by achow101)
  • #28690 (build: Introduce internal kernel library by TheCharlatan)
  • #25390 (sync: introduce a thread-safe generic container and use it to remove a bunch of "GlobalMutex"es by vasild)

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.

@DrahtBot DrahtBot changed the title util: Remove DirIsWritable, GetUniquePath util: Remove DirIsWritable, GetUniquePath Jul 14, 2023
@fanquake
Copy link
Member

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

src/Makefile.am Outdated Show resolved Hide resolved
@TheCharlatan
Copy link
Contributor

Nice, Concept ACK.

Copy link
Contributor

@TheCharlatan TheCharlatan left a 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)));
Copy link
Contributor

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.

Copy link
Member Author

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) {
Copy link
Contributor

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.

Copy link
Member Author

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.

@hebasto
Copy link
Member

hebasto commented Oct 4, 2023

Concept ACK.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

@@ -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;
Copy link
Member

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?

Copy link
Member Author

@maflcko maflcko Oct 26, 2023

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.

Copy link
Member Author

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 enumerate all possible "return values" of TestOtherProcess.

This makes it easier to add more Error cases in the future. Also, add
missing util namespace.
MarcoFalke added 2 commits October 26, 2023 10:32
This allows the caller to remove a call to DirIsWritable(), which did a
similar check. Users should not notice any different behavior.
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ACK fa3da62

Copy link
Member

@hebasto hebasto left a 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.

@fanquake fanquake merged commit f48a789 into bitcoin:master Dec 13, 2023
16 checks passed
@maflcko maflcko deleted the 2307-remove-fs-code- branch December 13, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants