Remove fs::relative call and fix listwalletdir tests #14561

pull promag wants to merge 1 commits into bitcoin:master from promag:2018-10-fix-listwalletdir changing 2 files +11 −6
  1. promag commented at 11:30 am on October 24, 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.

    Based on #14559

  2. fanquake added the label Wallet on Oct 24, 2018
  3. promag force-pushed on Oct 24, 2018
  4. in src/wallet/walletutil.cpp:60 in ee15451f65 outdated
    56     std::vector<fs::path> paths;
    57 
    58-    for (auto it = fs::recursive_directory_iterator(wallet_dir); it != end(it); ++it) {
    59+    for (auto it = fs::recursive_directory_iterator(wallet_dir); it != fs::recursive_directory_iterator(); ++it) {
    60+        assert(it->path().string().compare(0, base.size(), base) == 0);
    61+        const std::string relative = it->path().string().substr(base.size() + 1); // Account for directory separator
    


    ryanofsky commented at 2:00 pm on October 24, 2018:
    It might be good to pull this logic out into a reusable fs::path LexicallyRelative(fs::path path, fs::path base) function. Then later we could replace it with standard lexically_relative.

    promag commented at 2:33 pm on October 24, 2018:
    Done.
  5. ryanofsky commented at 2:05 pm on October 24, 2018: member
    utACK ee15451f65c73bc51a7fb2e3fda105488ce16915 (just this commit, not base commits). I think this fix is preferable to the one in #14531 because it avoids getting confused by symlinks and duplicating work already done by the directory iterator.
  6. promag force-pushed on Oct 24, 2018
  7. ryanofsky approved
  8. ryanofsky commented at 3:10 pm on October 24, 2018: member

    utACK 7879ac6ee8efbefafcecef7a0f7fcbdf888bb957 (last commit only). Only change is adding LexicallyRelative function. There are some other changes I might want to make on top of this:

    • Writing tests for LexicallyRelative
    • Adding comment saying it could be replaced in the future with c++17 path::lexically_relative
    • Throwing exception instead of asserting
    • Checking path.string()[base.string().size()] character is a separator.

    But I think 7879ac6ee8efbefafcecef7a0f7fcbdf888bb957 is a nice minimal fix that will restore compatibility with previous boost versions.

  9. promag commented at 3:21 pm on October 24, 2018: member
    I will rebase once base is merged.
  10. DrahtBot added the label Needs rebase on Oct 24, 2018
  11. promag force-pushed on Oct 24, 2018
  12. promag commented at 7:26 pm on October 24, 2018: member
    Rebased.
  13. DrahtBot removed the label Needs rebase on Oct 24, 2018
  14. fanquake added this to the "Blockers" column in a project

  15. ken2812221 approved
  16. ken2812221 commented at 3:25 am on October 25, 2018: contributor
    utACK 8c38f991f8925834c3db390d3c15e42a13c8984c
  17. in src/wallet/walletutil.cpp:54 in 8c38f991f8 outdated
    48@@ -49,15 +49,21 @@ static bool IsBerkeleyBtree(const fs::path& path)
    49     return data == 0x00053162 || data == 0x62310500;
    50 }
    51 
    52+static fs::path LexicallyRelative(const fs::path& path, const fs::path& base)
    53+{
    54+    assert(path.string().compare(0, base.string().size(), base.string()) == 0);
    


    laanwj commented at 1:07 pm on October 25, 2018:
    I don’t like using assert as error handling here

    ryanofsky commented at 2:16 pm on October 25, 2018:

    I don’t like using assert as error handling here

    I previously suggested an exception instead of aborting (https://github.com/bitcoin/bitcoin/pull/14561#pullrequestreview-167964007), but this isn’t runtime error handling. It is checking an assumption the list code is making about the behavior of recursive_directory_iterator. In the new version of this PR that drops the assert, the assumption is no longer documented or checked, and if it’s violated ListWalletDirs will return garbage instead of aborting.

  18. promag commented at 2:02 pm on October 25, 2018: member
    @ryanofsky @ken2812221 please review updated version which inlines the function.
  19. laanwj commented at 2:02 pm on October 25, 2018: member
    utACK
  20. ryanofsky approved
  21. ryanofsky commented at 2:17 pm on October 25, 2018: member
    utACK a0daca2342dbab588db0461ad292d4a4a0d8879c which inlines the lexically relative logic again. I think this is less readable and more fragile than what I suggested, but it’s fine if others like this approach.
  22. Remove fs::relative call and fix listwalletdir tests
    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.
    ed2e18398b
  23. promag force-pushed on Oct 25, 2018
  24. promag commented at 2:35 pm on October 25, 2018: member
    Squashed.
  25. laanwj commented at 2:48 pm on October 25, 2018: member

    utACK a0daca2 which inlines the lexically relative logic again. I think this is less readable and more fragile than what I suggested, but it’s fine if others like this approach.

    we had some discussion about this on IRC. I was fine with having it an utility function, I just believe utility functions need proper error handling and not ‘assert’, that was my only point that caused @promag to change it to this.

  26. ryanofsky approved
  27. ryanofsky commented at 2:53 pm on October 25, 2018: member
    utACK squashed ed2e18398b3ab657e98e3e1fe135cbf8dd94fda3
  28. promag commented at 2:53 pm on October 25, 2018: member

    Honestly I don’t want to provide the utility function, it wasn’t needed until now, I doubt it will be needed and sadly boost 1.47 doesn’t have it. But if needed this can be extracted and unit tested. Until then this is covered by listwalletdir RPC and soon also exposed in the UI.

    I’m also happy to follow up with previous @ryanofsky suggestions. I just think that the goal should be to fix boost build and listwalletdir tests first.

    BTW, thanks for your time reviewers.

  29. kallewoof commented at 11:28 pm on October 25, 2018: member
    Compiles and tests run fine on Debian Jessie PPC (big endian).
  30. laanwj commented at 11:25 am on October 26, 2018: member

    Honestly I don’t want to provide the utility function, it wasn’t needed until now, I doubt it will be needed

    Thank you for being clear, that’s completely acceptable.

    FWIW to me, too, it seems to small of a code unit to have much advantage of clarity of factoring it out. Let’s just leave it at this.

  31. laanwj merged this on Oct 26, 2018
  32. laanwj closed this on Oct 26, 2018

  33. laanwj referenced this in commit d50c996a14 on Oct 26, 2018
  34. promag deleted the branch on Oct 26, 2018
  35. fanquake removed this from the "Blockers" column in a project

  36. deadalnix referenced this in commit 65d491f19b on Mar 24, 2020
  37. jonspock referenced this in commit f94833af92 on Aug 14, 2020
  38. ftrader referenced this in commit 936228fb8a on Aug 17, 2020
  39. jonspock referenced this in commit f5e8669b4a on Aug 27, 2020
  40. jonspock referenced this in commit c5474b866e on Aug 28, 2020
  41. jonspock referenced this in commit 3be35ebd81 on Sep 4, 2020
  42. jonspock referenced this in commit a7ea846a0c on Sep 5, 2020
  43. jonspock referenced this in commit e3f9f40612 on Sep 6, 2020
  44. jonspock referenced this in commit 0b56e4dc75 on Sep 13, 2020
  45. jonspock referenced this in commit 775fc10c71 on Sep 13, 2020
  46. jonspock referenced this in commit 2bdafeac59 on Sep 15, 2020
  47. jonspock referenced this in commit 734fc9d93e on Sep 16, 2020
  48. jonspock referenced this in commit 51a2f16e79 on Sep 16, 2020
  49. jonspock referenced this in commit 2de5267945 on Sep 17, 2020
  50. jonspock referenced this in commit 56f3a87785 on Sep 18, 2020
  51. jonspock referenced this in commit bdbd9d3ebe on Sep 21, 2020
  52. jonspock referenced this in commit 8a28d4ca85 on Sep 21, 2020
  53. jonspock referenced this in commit 12f0a0fd7d on Sep 23, 2020
  54. jonspock referenced this in commit 25432a513f on Sep 24, 2020
  55. proteanx referenced this in commit 3fc8e79036 on Sep 25, 2020
  56. Munkybooty referenced this in commit 48dfb25f78 on Jul 21, 2021
  57. 5tefan referenced this in commit b7d97ccb2f on Aug 13, 2021
  58. 5tefan referenced this in commit a9858f167d on Aug 14, 2021
  59. 5tefan referenced this in commit 4b2580102e on Aug 14, 2021
  60. PastaPastaPasta referenced this in commit f370f41210 on Aug 16, 2021
  61. 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-11-17 03:12 UTC

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