Use std::filesystem::rename() instead of std::rename(). We rely on the
destination to be overwritten if it exists, but std::rename()'s behavior
is implementation-defined in this case.
util: use stronger-guarantee rename method #20435
pull vasild wants to merge 1 commits into bitcoin:master from vasild:rename changing 2 files +11 −7-
vasild commented at 2:37 PM on November 20, 2020: contributor
-
maflcko commented at 2:43 PM on November 20, 2020: member
Please update doc/dependencies to gcc 8 (from 7), as std::fs is not included in gcc 7
Edit: And clang-7
- vasild force-pushed on Nov 20, 2020
-
vasild commented at 3:27 PM on November 20, 2020: contributor
Updated. I am not sure if this PR shouldn't be put on hold until CentOS 23 starts shipping with a recent enough compiler?
-
maflcko commented at 3:29 PM on November 20, 2020: member
Maybe adding
-lstdc++fsto the build flags via configure by default fixes the compile errors? - DrahtBot added the label Docs on Nov 20, 2020
- DrahtBot added the label Utils/log/libs on Nov 20, 2020
- maflcko removed the label Docs on Nov 20, 2020
-
laanwj commented at 10:10 AM on November 23, 2020: member
Concept ACK! That's another WIN32 specific hack less.
But yes it's probably going to be a looong time before this can be merged.
-
vasild commented at 10:34 AM on November 23, 2020: contributor
I will leave this as is (open, with failing CI) until the compilers we support catch up with C++17 filesystem support.
- maflcko added the label Waiting for author on Nov 23, 2020
-
DrahtBot commented at 11:11 AM on November 23, 2020: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
No conflicts as of last run.
- DrahtBot added the label Needs rebase on Nov 24, 2020
- vasild force-pushed on Nov 24, 2020
- DrahtBot removed the label Needs rebase on Nov 24, 2020
-
laanwj commented at 12:30 PM on December 3, 2020: member
I will leave this as is (open, with failing CI) until the compilers we support catch up with C++17 filesystem support.
I don't think labeling this as "waiting for author" is quite right.
- laanwj added this to the milestone Future on Dec 3, 2020
- maflcko removed the label Waiting for author on Dec 15, 2020
- maflcko added the label Waiting for other on Dec 15, 2020
- fanquake referenced this in commit 67eae69f3f on Sep 28, 2021
- maflcko removed the label Waiting for other on Sep 28, 2021
-
in src/util/system.cpp:1013 in 166b1542d7 outdated
1006 | @@ -1005,15 +1007,15 @@ void ArgsManager::LogArgs() const 1007 | logArgsPrefix("Command-line arg:", "", m_settings.command_line_options); 1008 | } 1009 | 1010 | +/** 1011 | + * Rename src to dest. 1012 | + * @return true if the rename was successful. 1013 | + */
maflcko commented at 6:21 AM on September 28, 2021:Shouldn't doxygen be in the
.hfile?
vasild commented at 8:06 AM on September 28, 2021:Right, moved.
vasild force-pushed on Sep 28, 2021fanquake commented at 8:10 AM on September 28, 2021: memberI don't think this PR depends on #20744. @fanquake, why do you think this PR cannot be merged before #20744?
Because we are either using
boost::filesystemorstd::filesystem. We're not going to have the repo exist in some awkward middle ground where we are using both. In any case, usingstd::filesystemis not necessarily straight forward, and likely requires the changes in #22937 before it can be used.fanquake commented at 8:13 AM on September 28, 2021: memberAnother reason is that this doesn't have any build system support for properly using
std::filesystem, and the additional linker flags that may be needed, i.e https://github.com/bitcoin/bitcoin/pull/20744/commits/721928821f1623265db9c07f2fcef49a356d477f.DrahtBot added the label Needs rebase on Oct 15, 2021in src/util/system.cpp:1069 in 99b151df9c outdated
1071 | -#else 1072 | - int rc = std::rename(src.string().c_str(), dest.string().c_str()); 1073 | - return (rc == 0); 1074 | -#endif /* WIN32 */ 1075 | + std::error_code error; 1076 | + std::filesystem::rename(src.string(), dest.string(), error);
ryanofsky commented at 4:08 PM on November 1, 2021:In commit "util: use stronger-guarantee rename method" (99b151df9c074f60150c5eb777ed98bfd7118e91)
This will result in narrow string conversion on windows, and after #22937 will be a compiler error. Should be easy to fix by changing to:
std::filesystem::rename(src.native(), dest.native(), error);This should also work after #20744, but after #20744 it could be simplified more to
std::filesystem::rename(src, dest, error);
vasild commented at 1:18 PM on November 2, 2021:Used just
srcanddest, thanks!ryanofsky approvedryanofsky commented at 4:18 PM on November 1, 2021: contributorConditional code review ACK 99b151df9c074f60150c5eb777ed98bfd7118e91 if this is rebased and
.string()is replaced by.native()(see comment below).This is just a review of the c++ code, disregarding build issues. IIUC the new rename function may not be callable on all platforms without some of the build changes in #20744.
a9ab42ca97util: use stronger-guarantee rename method
Use std::filesystem::rename() instead of std::rename(). We rely on the destination to be overwritten if it exists, but std::rename()'s behavior is implementation-defined in this case.
vasild force-pushed on Nov 2, 2021DrahtBot removed the label Needs rebase on Nov 2, 2021vasild commented at 1:21 PM on November 2, 2021: contributor99b151df9c...a9ab42ca97: rebase due to conflicts and pick up a suggestion.This now depends on #20744 in two ways:
- Build system changes to make it compile on all platforms
- Assumes that our custom
fs::pathisstd::filesystem::path(passes a variable of typefs::pathtostd::filesystem::rename()).
Invalidates ACK from @ryanofsky (conditional)
ryanofsky approvedDrahtBot added the label Needs rebase on Feb 3, 2022DrahtBot commented at 4:12 PM on February 3, 2022: contributor<!--cf906140f33d8803c4a75a2196329ecb-->
🐙 This pull request conflicts with the target branch and needs rebase.
<sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>
fanquake closed this on Feb 10, 2022vasild deleted the branch on Feb 10, 2022maflcko referenced this in commit b79c40b057 on Feb 11, 2022sidhujag referenced this in commit ed278f1df3 on Feb 11, 2022bitcoin locked this on Feb 10, 2023maflcko removed this from the milestone Future on Jul 23, 2025
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-01 03:14 UTC
More mirrored repositories can be found on mirror.b10c.me