Skip to content

Commit 6342348

Browse files
committed
Merge bitcoin/bitcoin#28076: util: Replace std::filesystem with util/fs.h
bbbbdb0 ci: Add filesystem lint check (MarcoFalke) fada2f9 refactor: Replace <filesystem> with <util/fs.h> (MarcoFalke) Pull request description: Using `std::filesystem` is problematic: * There is a `fs` namespace wrapper for it. So having two ways to achieve the same is confusing. * Not using the `fs` wrapper is dangerous and buggy, because it disables known bugs by deleting problematic functions. Fix all issues by removing use of it and adding a linter to avoid using it again in the future. ACKs for top commit: TheCharlatan: ACK bbbbdb0 fanquake: ACK bbbbdb0 🦀 Tree-SHA512: 0e2d49742b08eb2635e6fce41485277cb9c40fe20b81017c391d3472a43787db1278a236825714ca1e41c9d2f59913865cfb0c649e3c8ab1fb598c849f80c660
2 parents 29c2c90 + bbbbdb0 commit 6342348

File tree

13 files changed

+127
-9
lines changed

13 files changed

+127
-9
lines changed

.cirrus.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ task:
8484
memory: 1G
8585
# For faster CI feedback, immediately schedule the linters
8686
<< : *CREDITS_TEMPLATE
87+
test_runner_cache:
88+
folder: "/lint_test_runner"
89+
fingerprint_script: echo $CIRRUS_TASK_NAME $(git rev-parse HEAD:test/lint/test_runner)
8790
python_cache:
8891
folder: "/python_build"
8992
fingerprint_script: cat .python-version /etc/os-release

ci/lint/04_install.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export PATH="${PYTHON_PATH}/bin:${PATH}"
3333
command -v python3
3434
python3 --version
3535

36+
export LINT_RUNNER_PATH="/lint_test_runner"
37+
if [ ! -d "${LINT_RUNNER_PATH}" ]; then
38+
${CI_RETRY_EXE} apt-get install -y cargo
39+
(
40+
cd ./test/lint/test_runner || exit 1
41+
cargo build
42+
mkdir -p "${LINT_RUNNER_PATH}"
43+
mv target/debug/test_runner "${LINT_RUNNER_PATH}"
44+
)
45+
fi
46+
3647
${CI_RETRY_EXE} pip3 install \
3748
codespell==2.2.5 \
3849
flake8==6.1.0 \

ci/lint/06_script.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test/lint/git-subtree-check.sh src/secp256k1
3030
test/lint/git-subtree-check.sh src/minisketch
3131
test/lint/git-subtree-check.sh src/leveldb
3232
test/lint/git-subtree-check.sh src/crc32c
33+
RUST_BACKTRACE=1 "${LINT_RUNNER_PATH}/test_runner"
3334
test/lint/check-doc.py
3435
test/lint/all-lint.py
3536

ci/lint/container-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export LC_ALL=C
1111
git config --global --add safe.directory /bitcoin
1212

1313
export PATH="/python_build/bin:${PATH}"
14+
export LINT_RUNNER_PATH="/lint_test_runner"
1415

1516
if [ -z "$1" ]; then
1617
LOCAL_BRANCH=1 bash -ic "./ci/lint/06_script.sh"

src/bitcoin-chainstate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
#include <scheduler.h>
2727
#include <script/sigcache.h>
2828
#include <util/chaintype.h>
29+
#include <util/fs.h>
2930
#include <util/thread.h>
3031
#include <validation.h>
3132
#include <validationinterface.h>
3233

3334
#include <cassert>
3435
#include <cstdint>
35-
#include <filesystem>
3636
#include <functional>
3737
#include <iosfwd>
3838
#include <memory>
@@ -50,8 +50,8 @@ int main(int argc, char* argv[])
5050
<< " BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
5151
return 1;
5252
}
53-
std::filesystem::path abs_datadir = std::filesystem::absolute(argv[1]);
54-
std::filesystem::create_directories(abs_datadir);
53+
fs::path abs_datadir{fs::absolute(argv[1])};
54+
fs::create_directories(abs_datadir);
5555

5656

5757
// SETUP: Context

src/common/args.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <cstdint>
2929
#include <cstdlib>
3030
#include <cstring>
31-
#include <filesystem>
3231
#include <map>
3332
#include <optional>
3433
#include <stdexcept>

src/policy/fees.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,8 @@ void CBlockPolicyEstimator::FlushUnconfirmed()
10441044

10451045
std::chrono::hours CBlockPolicyEstimator::GetFeeEstimatorFileAge()
10461046
{
1047-
auto file_time = std::filesystem::last_write_time(m_estimation_filepath);
1048-
auto now = std::filesystem::file_time_type::clock::now();
1047+
auto file_time{fs::last_write_time(m_estimation_filepath)};
1048+
auto now{fs::file_time_type::clock::now()};
10491049
return std::chrono::duration_cast<std::chrono::hours>(now - file_time);
10501050
}
10511051

src/util/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static inline path PathFromString(const std::string& string)
184184
* already exists or is a symlink to an existing directory.
185185
* This is a temporary workaround for an issue in libstdc++ that has been fixed
186186
* upstream [PR101510].
187+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510
187188
*/
188189
static inline bool create_directories(const std::filesystem::path& p)
189190
{

src/util/fs_helpers.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111

1212
#include <logging.h>
1313
#include <sync.h>
14-
#include <tinyformat.h>
1514
#include <util/fs.h>
1615
#include <util/getuniquepath.h>
1716
#include <util/syserror.h>
1817

1918
#include <cerrno>
20-
#include <filesystem>
2119
#include <fstream>
2220
#include <map>
2321
#include <memory>
@@ -263,7 +261,7 @@ bool RenameOver(fs::path src, fs::path dest)
263261
{
264262
#ifdef __MINGW64__
265263
// This is a workaround for a bug in libstdc++ which
266-
// implements std::filesystem::rename with _wrename function.
264+
// implements fs::rename with _wrename function.
267265
// This bug has been fixed in upstream:
268266
// - GCC 10.3: 8dd1c1085587c9f8a21bb5e588dfe1e8cdbba79e
269267
// - GCC 11.1: 1dfd95f0a0ca1d9e6cbc00e6cbfd1fa20a98f312

test/lint/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ DOCKER_BUILDKIT=1 docker build -t bitcoin-linter --file "./ci/lint_imagefile" ./
1313
Building the container can be done every time, because it is fast when the
1414
result is cached and it prevents issues when the image changes.
1515

16+
test runner
17+
===========
18+
19+
To run the checks in the test runner outside the docker, use:
20+
21+
```sh
22+
( cd ./test/lint/test_runner/ && cargo fmt && cargo clippy && cargo run )
23+
```
1624

1725
check-doc.py
1826
============

0 commit comments

Comments
 (0)