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. promag cross-referenced this on Oct 20, 2018 from issue travis: Compile once on xenial by MarcoFalke
  3. fanquake added the label Wallet on Oct 20, 2018
  4. MarcoFalke added the label Refactoring on Oct 20, 2018
  5. 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.

  6. promag cross-referenced this on Oct 20, 2018 from issue wallet: Add ListWalletDir utility function by promag
  7. wallet: Fix duplicate fileid 8c08159e8b
  8. promag cross-referenced this on Oct 21, 2018 from issue walletutil.cpp build issue by wkibbler
  9. promag force-pushed on Oct 22, 2018
  10. promag force-pushed on Oct 22, 2018
  11. promag force-pushed on Oct 22, 2018
  12. promag force-pushed on Oct 22, 2018
  13. practicalswift cross-referenced this on Oct 22, 2018 from issue Enable flake8 rule E225 which checks for missing whitespace around op… by jbampton
  14. promag cross-referenced this on Oct 22, 2018 from issue [bugfix] wallet: Fix duplicate fileid detection by ken2812221
  15. promag force-pushed on Oct 22, 2018
  16. promag force-pushed on Oct 23, 2018
  17. laanwj added this to the "Blockers" column in a project

  18. DrahtBot commented at 10:05 PM on October 23, 2018: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->Reviewers, this pull request conflicts with the following ones:

    • #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.

  19. DrahtBot cross-referenced this on Oct 23, 2018 from issue Try to use posix_fadvise with CBufferedFile by luke-jr
  20. tests: add test case for loading copied wallet twice ef16fc5da6
  21. appveyor: Enable multiwallet test 118f64736d
  22. 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.

  23. promag cross-referenced this on Oct 24, 2018 from issue appveyor: Enable multiwallet tests by ken2812221
  24. 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.

  25. 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.

    GetRelativePath(path, base, base / "bar");
    
  26. 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.

  27. Add GetRelativePath utility function c97d7e011f
  28. qa: Add tests for GetRelativePath 8d0792bbc9
  29. 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
  30. promag force-pushed on Oct 24, 2018
  31. promag commented at 12:13 PM on October 24, 2018: member

    Alternative approach in #14561.

  32. 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?

  33. 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.

  34. ryanofsky commented at 2:10 PM on October 24, 2018: contributor

    Would suggest closing this. I think the fix in #14561 is simpler and more correct.

  35. promag commented at 2:18 PM on October 24, 2018: member

    Agree @ryanofsky.

  36. promag closed this on Oct 24, 2018

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

  39. bitcoin 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: 2026-05-20 06:54 UTC