Skip to content

Commit

Permalink
Merge bitcoin#27254: refactor: Extract util/fs from util/system
Browse files Browse the repository at this point in the history
00e9b97 refactor: Move fs.* to util/fs.* (TheCharlatan)
106b46d Add missing fs.h includes (TheCharlatan)
b202b3d Add missing cstddef include in assumptions.h (TheCharlatan)
18fb363 refactor: Extract util/fs_helpers from util/system (Ben Woosley)

Pull request description:

  This pull request is part of the `libbitcoinkernel` project bitcoin#24303 https://github.com/bitcoin/bitcoin/projects/18 and more specifically its "Step 2: Decouple most non-consensus code from libbitcoinkernel". This commit was originally authored by empact and is taken from its parent PR bitcoin#25152.

  #### Context

  There is an ongoing effort to decouple the `ArgsManager` used for command line parsing user-provided arguments from the libbitcoinkernel library (bitcoin#25290, bitcoin#25487, bitcoin#25527, bitcoin#25862, bitcoin#26177, and bitcoin#27125). The `ArgsManager` is defined in `system.h`. A similar pull request extracting functionality from `system.h` has been merged in bitcoin#27238.

  #### Changes

  Next to providing better code organization, this PR removes some reliance of the tree of libbitcoinkernel header includes on `system.h` (and thus the `ArgsManager` definition) by moving filesystem related functions out of the `system.*` files.

  There is already a pair of `fs.h` / `fs.cpp` in the top-level `src/` directory. They were not combined with the files introduced here, to keep the patch cleaner and more importantly because they are often included without the utility functions. The new files are therefore named `fs_helpers` and the existing `fs` files are moved into the util directory.

  Further commits splitting more functionality out of `system.h` are still in bitcoin#25152 and will be submitted in separate PRs once this PR has been processed.

ACKs for top commit:
  hebasto:
    ACK 00e9b97

Tree-SHA512: 31422f148d14ba3c843b99b1550a6fd77c77f350905ca324f93d4f97b652246bc58fa9696c64d1201979cf88733e40be02d262739bb7d417cf22bf506fdb7666
  • Loading branch information
fanquake committed Apr 3, 2023
2 parents 5150e28 + 00e9b97 commit 369d4c0
Show file tree
Hide file tree
Showing 94 changed files with 480 additions and 412 deletions.
9 changes: 6 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ BITCOIN_CORE_H = \
deploymentstatus.h \
external_signer.h \
flatfile.h \
fs.h \
headerssync.h \
httprpc.h \
httpserver.h \
Expand Down Expand Up @@ -285,6 +284,8 @@ BITCOIN_CORE_H = \
util/exception.h \
util/fastrange.h \
util/fees.h \
util/fs.h \
util/fs_helpers.h \
util/getuniquepath.h \
util/golombrice.h \
util/hash_type.h \
Expand Down Expand Up @@ -694,7 +695,6 @@ libbitcoin_util_a_SOURCES = \
support/lockedpool.cpp \
chainparamsbase.cpp \
clientversion.cpp \
fs.cpp \
logging.cpp \
random.cpp \
randomenv.cpp \
Expand All @@ -707,6 +707,8 @@ libbitcoin_util_a_SOURCES = \
util/error.cpp \
util/exception.cpp \
util/fees.cpp \
util/fs.cpp \
util/fs_helpers.cpp \
util/getuniquepath.cpp \
util/hasher.cpp \
util/sock.cpp \
Expand Down Expand Up @@ -908,7 +910,6 @@ libbitcoinkernel_la_SOURCES = \
deploymentinfo.cpp \
deploymentstatus.cpp \
flatfile.cpp \
fs.cpp \
hash.cpp \
kernel/chain.cpp \
kernel/checks.cpp \
Expand Down Expand Up @@ -951,6 +952,8 @@ libbitcoinkernel_la_SOURCES = \
uint256.cpp \
util/check.cpp \
util/exception.cpp \
util/fs.cpp \
util/fs_helpers.cpp \
util/getuniquepath.cpp \
util/hasher.cpp \
util/moneystr.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <chainparams.h>
#include <clientversion.h>
#include <cstdint>
#include <fs.h>
#include <hash.h>
#include <logging.h>
#include <logging/timer.h>
Expand All @@ -19,6 +18,8 @@
#include <streams.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/settings.h>
#include <util/system.h>
#include <util/translation.h>
Expand Down
2 changes: 1 addition & 1 deletion src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef BITCOIN_ADDRDB_H
#define BITCOIN_ADDRDB_H

#include <fs.h>
#include <net_types.h> // For banmap_t
#include <univalue.h>
#include <util/fs.h>

#include <optional>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion src/banman.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include <addrdb.h>
#include <common/bloom.h>
#include <fs.h>
#include <net_types.h> // For banmap_t
#include <sync.h>
#include <util/fs.h>

#include <chrono>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <bench/bench.h>

#include <fs.h>
#include <test/util/setup_common.h>
#include <util/fs.h>
#include <util/string.h>

#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/bench/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef BITCOIN_BENCH_BENCH_H
#define BITCOIN_BENCH_BENCH_H

#include <fs.h>
#include <util/fs.h>
#include <util/macros.h>

#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <clientversion.h>
#include <crypto/sha256.h>
#include <fs.h>
#include <util/fs.h>
#include <util/strencodings.h>
#include <util/system.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <core_io.h>
#include <fs.h>
#include <key_io.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
Expand All @@ -21,6 +20,7 @@
#include <script/signingprovider.h>
#include <univalue.h>
#include <util/exception.h>
#include <util/fs.h>
#include <util/moneystr.h>
#include <util/rbf.h>
#include <util/strencodings.h>
Expand Down
4 changes: 2 additions & 2 deletions src/common/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/init.h>
#include <chainparams.h>
#include <fs.h>
#include <common/init.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/system.h>
#include <util/translation.h>

Expand Down
1 change: 1 addition & 0 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef BITCOIN_COMPAT_ASSUMPTIONS_H
#define BITCOIN_COMPAT_ASSUMPTIONS_H

#include <cstddef>
#include <limits>

// Assumption: We assume that the macro NDEBUG is not defined.
Expand Down
4 changes: 2 additions & 2 deletions src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include <dbwrapper.h>

#include <fs.h>
#include <logging.h>
#include <random.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/strencodings.h>
#include <util/system.h>

#include <algorithm>
#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#define BITCOIN_DBWRAPPER_H

#include <clientversion.h>
#include <fs.h>
#include <logging.h>
#include <serialize.h>
#include <span.h>
#include <streams.h>
#include <util/fs.h>

#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion src/flatfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <flatfile.h>
#include <logging.h>
#include <tinyformat.h>
#include <util/system.h>
#include <util/fs_helpers.h>

FlatFileSeq::FlatFileSeq(fs::path dir, const char* prefix, size_t chunk_size) :
m_dir(std::move(dir)),
Expand Down
2 changes: 1 addition & 1 deletion src/flatfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <string>

#include <fs.h>
#include <serialize.h>
#include <util/fs.h>

struct FlatFilePos
{
Expand Down
2 changes: 1 addition & 1 deletion src/i2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include <compat/compat.h>
#include <compat/endian.h>
#include <crypto/sha256.h>
#include <fs.h>
#include <i2p.h>
#include <logging.h>
#include <netaddress.h>
#include <netbase.h>
#include <random.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/readwritefile.h>
#include <util/sock.h>
#include <util/spanparsing.h>
Expand Down
2 changes: 1 addition & 1 deletion src/i2p.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define BITCOIN_I2P_H

#include <compat/compat.h>
#include <fs.h>
#include <netaddress.h>
#include <sync.h>
#include <util/fs.h>
#include <util/sock.h>
#include <util/threadinterrupt.h>

Expand Down
1 change: 1 addition & 0 deletions src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <hash.h>
#include <index/blockfilterindex.h>
#include <node/blockstorage.h>
#include <util/fs_helpers.h>
#include <util/system.h>
#include <validation.h>

Expand Down
3 changes: 2 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <chainparams.h>
#include <consensus/amount.h>
#include <deploymentstatus.h>
#include <fs.h>
#include <hash.h>
#include <httprpc.h>
#include <httpserver.h>
Expand Down Expand Up @@ -70,6 +69,8 @@
#include <txmempool.h>
#include <util/asmap.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/moneystr.h>
#include <util/strencodings.h>
#include <util/string.h>
Expand Down
3 changes: 2 additions & 1 deletion src/init/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#endif

#include <clientversion.h>
#include <fs.h>
#include <logging.h>
#include <node/interface_ui.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/string.h>
#include <util/system.h>
#include <util/time.h>
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#define BITCOIN_INTERFACES_WALLET_H

#include <consensus/amount.h>
#include <fs.h>
#include <interfaces/chain.h> // For ChainClient
#include <pubkey.h> // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation)
#include <script/standard.h> // For CTxDestination
#include <support/allocators/secure.h> // For SecureString
#include <util/fs.h>
#include <util/message.h>
#include <util/result.h>
#include <util/ui_change_type.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <fs.h>
#include <interfaces/init.h>
#include <interfaces/ipc.h>
#include <ipc/capnp/protocol.h>
#include <ipc/process.h>
#include <ipc/protocol.h>
#include <logging.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/system.h>

#include <cstdio>
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <fs.h>
#include <ipc/process.h>
#include <ipc/protocol.h>
#include <mp/util.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/strencodings.h>

#include <cstdint>
Expand Down
2 changes: 2 additions & 0 deletions src/ipc/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef BITCOIN_IPC_PROCESS_H
#define BITCOIN_IPC_PROCESS_H

#include <util/fs.h>

#include <memory>
#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/mempool_persist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <clientversion.h>
#include <consensus/amount.h>
#include <fs.h>
#include <logging.h>
#include <primitives/transaction.h>
#include <serialize.h>
Expand All @@ -15,7 +14,8 @@
#include <sync.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/system.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/time.h>
#include <validation.h>

Expand Down
2 changes: 1 addition & 1 deletion src/kernel/mempool_persist.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef BITCOIN_KERNEL_MEMPOOL_PERSIST_H
#define BITCOIN_KERNEL_MEMPOOL_PERSIST_H

#include <fs.h>
#include <util/fs.h>

class Chainstate;
class CTxMemPool;
Expand Down
2 changes: 1 addition & 1 deletion src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <fs.h>
#include <logging.h>
#include <util/fs.h>
#include <util/string.h>
#include <util/threadnames.h>
#include <util/time.h>
Expand Down
2 changes: 1 addition & 1 deletion src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef BITCOIN_LOGGING_H
#define BITCOIN_LOGGING_H

#include <fs.h>
#include <threadsafety.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/string.h>

#include <atomic>
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <compat/compat.h>
#include <consensus/consensus.h>
#include <crypto/sha256.h>
#include <fs.h>
#include <i2p.h>
#include <logging.h>
#include <net_permissions.h>
Expand All @@ -27,6 +26,7 @@
#include <protocol.h>
#include <random.h>
#include <scheduler.h>
#include <util/fs.h>
#include <util/sock.h>
#include <util/strencodings.h>
#include <util/syscall_sandbox.h>
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <clientversion.h>
#include <consensus/validation.h>
#include <flatfile.h>
#include <fs.h>
#include <hash.h>
#include <logging.h>
#include <kernel/chainparams.h>
Expand All @@ -18,6 +17,7 @@
#include <signet.h>
#include <streams.h>
#include <undo.h>
#include <util/fs.h>
#include <util/syscall_sandbox.h>
#include <util/system.h>
#include <validation.h>
Expand Down
Loading

0 comments on commit 369d4c0

Please sign in to comment.