-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Replace fs::relative call with custom GetRelativePath #14531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/wallet/walletutil.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a unit test for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
73838a3 to
ca5df04
Compare
8a4d526 to
ad779bc
Compare
Reviewers, this pull request conflicts with the following ones:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/util.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added parent != parent.root_path() condition to the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.cppreference.com/w/cpp/filesystem/path/parent_path
The C++17 standard one is a little different from the experimental one.
src/test/util_tests.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this would cause infinity loop on Windows if base / "bar" exist.
GetRelativePath(path, base, base / "bar");
src/test/util_tests.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SetDataDir instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that but datadir seemed unrelated to this function. I can revert if there is a reason to do that.
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.
ad779bc to
8697d65
Compare
|
Alternative approach in #14561. |
| env = nullptr; | ||
| } else { | ||
| // 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. | ||
| // TODO: get rid of wild pointers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are "wild pointers"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is based on #14559, should comment there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it's #14320
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aka prchain.
|
Would suggest closing this. I think the fix in #14561 is simpler and more correct. |
|
Agree @ryanofsky. |
The implementation of
fs::relativeresolves symlinks which is not intendedin ListWalletDir. The replacement does what is required, and
listwalletdirRPCtests are fixed accordingly.
Also,
fs::recursive_directory_iteratoriteration is fixed to build with boost 1.47.