Replace fs::relative call with custom GetRelativePath #14531

pull promag wants to merge 6 commits into bitcoin:master from promag:2018-10-getrelativepath changing 8 files +82 −31
  1. promag commented at 1:33 pm on October 20, 2018: member

    The implementation of fs::relative resolves symlinks which is not intended in ListWalletDir. The replacement does what is required, and listwalletdir RPC tests are fixed accordingly.

    Also, fs::recursive_directory_iterator iteration is fixed to build with boost 1.47.

  2. fanquake added the label Wallet on Oct 20, 2018
  3. MarcoFalke added the label Refactoring on Oct 20, 2018
  4. in src/wallet/walletutil.cpp:59 in 126062abb7 outdated
    54+    fs::path relative, parent = path;
    55+    while (!parent.empty() && parent != base) {
    56+      relative = parent.filename() / relative;
    57+      parent = parent.parent_path();
    58+    }
    59+    return relative;
    


    laanwj commented at 1:49 pm on October 20, 2018:
    please add a unit test for this function

    promag commented at 11:44 pm on October 22, 2018:
    Done.
  5. wallet: Fix duplicate fileid 8c08159e8b
  6. promag force-pushed on Oct 22, 2018
  7. promag force-pushed on Oct 22, 2018
  8. promag force-pushed on Oct 22, 2018
  9. promag force-pushed on Oct 22, 2018
  10. promag force-pushed on Oct 22, 2018
  11. promag force-pushed on Oct 23, 2018
  12. laanwj added this to the "Blockers" column in a project

  13. DrahtBot commented at 10:05 pm on October 23, 2018: member
    • #14485 (Try to use posix_fadvise with CBufferedFile by luke-jr)
    • #14320 ([bugfix] wallet: Fix duplicate fileid detection by ken2812221)

    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.

  14. tests: add test case for loading copied wallet twice ef16fc5da6
  15. appveyor: Enable multiwallet test 118f64736d
  16. in test/functional/wallet_multiwallet.py:76 in ad779bc3a5 outdated
    72@@ -73,7 +73,7 @@ def wallet_file(name):
    73             wallet_names.remove('w7_symlink')
    74         extra_args = ['-wallet={}'.format(n) for n in wallet_names]
    75         self.start_node(0, extra_args)
    76-        assert_equal(set(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), set(['', 'w3', 'w2', 'sub/w5', 'w7', 'w7', 'w1', 'w8', 'w']))
    77+        assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), ['', 'sub/w5', 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
    


    promag commented at 9:53 am on October 24, 2018:
    Note to reviewers, I’ve removed the set() because it removes duplicate and that’s not the point — w7 was duplicate — sorted() is what’s needed.
  17. in src/util.cpp:197 in ad779bc3a5 outdated
    192+    if (!path.is_absolute() || !base.is_absolute()) return false;
    193+    fs::path relative, parent = path;
    194+    boost::system::error_code ec;
    195+    while (!parent.empty() && !fs::equivalent(parent, base, ec)) {
    196+        relative = parent.filename() / relative;
    197+        parent = parent.parent_path();
    


    ken2812221 commented at 10:10 am on October 24, 2018:
    On Windows, std::filesystem::path("C:\\").parent_path() == std::filesystem::path("C:\\"). It would be an infinity loop. (Only test std::filesystem in MSVC, doesn’t test boost::filesystem)

    promag commented at 10:50 am on October 24, 2018:
    Added parent != parent.root_path() condition to the loop.

    ryanofsky commented at 1:43 pm on October 24, 2018:

    On Windows, std::filesystem::path(“C:\”).parent_path() == std::filesystem::path(“C:\”)

    Workaround seems ok, but is this is a bug? Both boost filesystem and std::filesystem are supposed to return empty if the path contains a single element:

    https://en.cppreference.com/w/cpp/experimental/fs/path/parent_path https://www.boost.org/doc/libs/1_68_0/libs/filesystem/doc/reference.html#path-parent_path


    ken2812221 commented at 1:48 pm on October 24, 2018:
    https://en.cppreference.com/w/cpp/filesystem/path/parent_path The C++17 standard one is a little different from the experimental one.
  18. in src/test/util_tests.cpp:1236 in ad779bc3a5 outdated
    1231+
    1232+    BOOST_CHECK_EQUAL(GetRelativePath(path, base / "bar", base), true);
    1233+    BOOST_CHECK_EQUAL(path, "bar");
    1234+
    1235+    BOOST_CHECK_EQUAL(GetRelativePath(path, base / "foo/bar", base), true);
    1236+    BOOST_CHECK_EQUAL(path, "foo/bar");
    


    ken2812221 commented at 10:29 am on October 24, 2018:

    I assume this would cause infinity loop on Windows if base / “bar” exist.

    0GetRelativePath(path, base, base / "bar");
    
  19. in src/test/util_tests.cpp:1222 in ad779bc3a5 outdated
    1216@@ -1217,6 +1217,25 @@ BOOST_AUTO_TEST_CASE(test_DirIsWritable)
    1217     fs::remove(tmpdirname);
    1218 }
    1219 
    1220+BOOST_AUTO_TEST_CASE(test_GetRelativePath)
    1221+{
    1222+    fs::path base = fs::temp_directory_path();
    


    ken2812221 commented at 10:29 am on October 24, 2018:
    Use SetDataDir instead

    promag commented at 10:49 am on October 24, 2018:
    I had that but datadir seemed unrelated to this function. I can revert if there is a reason to do that.
  20. Add GetRelativePath utility function c97d7e011f
  21. qa: Add tests for GetRelativePath 8d0792bbc9
  22. Replace fs::relative call with GetRelativePath
    The implementation of fs::relative resolves symlinks which is not intended
    in ListWalletDir. The replacement does what is required, and listwalletdir
    tests are fixed accordingly.
    
    Also, building with boost 1.47 required 2 changes:
     - replace fs::relative with an alternative implementation;
     - fix fs::recursive_directory_iterator iteration.
    8697d658c8
  23. promag force-pushed on Oct 24, 2018
  24. promag commented at 12:13 pm on October 24, 2018: member
    Alternative approach in #14561.
  25. in src/wallet/db.h:29 in 8697d658c8
    24 #include <db_cxx.h>
    25 
    26 static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
    27 static const bool DEFAULT_WALLET_PRIVDB = true;
    28 
    29+struct BerkeleyFileid {
    


    laanwj commented at 12:19 pm on October 24, 2018:
    BerkeleyFileId?
  26. in src/wallet/db.cpp:831 in 8697d658c8
    825@@ -826,6 +826,10 @@ void BerkeleyDatabase::Flush(bool shutdown)
    826             LOCK(cs_db);
    827             g_dbenvs.erase(env->Directory().string());
    828             env = nullptr;
    829+        } else {
    830+            // To avoid accessing a map that has already deconstructed, do not call this when shutdown is true. g_dbenvs.erase would also erase this value.
    831+            // TODO: get rid of wild pointers
    


    laanwj commented at 12:44 pm on October 24, 2018:
    what are “wild pointers”?

    promag commented at 12:53 pm on October 24, 2018:
    This is based on #14559, should comment there.

    ken2812221 commented at 1:50 pm on October 24, 2018:
    Actually it’s #14320

    promag commented at 2:18 pm on October 24, 2018:
    aka prchain.
  27. ryanofsky commented at 2:10 pm on October 24, 2018: member
    Would suggest closing this. I think the fix in #14561 is simpler and more correct.
  28. promag commented at 2:18 pm on October 24, 2018: member
    Agree @ryanofsky.
  29. promag closed this on Oct 24, 2018

  30. promag deleted the branch on Oct 24, 2018
  31. fanquake removed this from the "Blockers" column in a project

  32. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-08 22:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me