Skip to content
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

Replace boost/fc filesystem #1011

Merged
merged 14 commits into from
Apr 18, 2023
Merged

Replace boost/fc filesystem #1011

merged 14 commits into from
Apr 18, 2023

Conversation

huangminghuang
Copy link
Contributor

@huangminghuang huangminghuang commented Apr 11, 2023

This PR

  • replaces all usage of boost and fc filesystem with std::filesystem,
  • creates a new class temp_cfile to replace the usages of boost::filesystem::unique_path which doesn't exists in std::filesystem due to safety concern,

Includes
AntelopeIO/appbase#15
AntelopeIO/appbase#16
AntelopeIO/appbase#17
AntelopeIO/appbase#18
AntelopeIO/appbase#19
AntelopeIO/appbase#20
AntelopeIO/appbase#21
AntelopeIO/chainbase#5
AntelopeIO/chainbase#6
AntelopeIO/chainbase#7
AntelopeIO/chainbase#8
AntelopeIO/chainbase#9

Resolves #620

@heifner heifner added the OCI Work exclusive to OCI team label Apr 11, 2023
@spoonincode
Copy link
Member

This change will require gcc 9.1+ or clang 9+ (technically libstdc++ & libc++). Please increase the minimum version in the root cmake,

leap/CMakeLists.txt

Lines 38 to 47 in 69c4e00

# http://stackoverflow.com/a/18369825
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
message(FATAL_ERROR "GCC version must be at least 8.0!")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
message(FATAL_ERROR "Clang version must be at least 5.0!")
endif()
endif()

(I think it's okay to remove AppleClang completely from this check; what's there isn't correct anyways)

@spoonincode
Copy link
Member

Can you test if it's possible to remove this workaround now

# jammy's boost 1.74 can stumble on an EXDEV via copy_file_range() it doesn't have a fallback for; re-eval once moving to std::filesystem
export TMPDIR="$PWD/tmp"
mkdir -p $TMPDIR

@stephenpdeos stephenpdeos modified the milestone: Leap v5.0.0-rc1 Apr 12, 2023
@spoonincode
Copy link
Member

There is at least one remaining boost::filesystem here


This causes a compile error in gcc12.

@heifner heifner requested review from spoonincode and heifner April 14, 2023 16:09
if(save_log)
{
// Cannot use fc::copy as it does not copy to an existing destination file
fc::rename(log_output.path().preferred_string(), DEEP_MIND_LOGFILE);
std::filesystem::copy(log_output_path, DEEP_MIND_LOGFILE, std::filesystem::copy_options::update_existing);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fc::rename() became fs::copy(.. update_existing). The semantics are clearly different between the two. Any reason for the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_output_path is derived from tmp of type temp_cfile object which would remove the file when tmp is out of scope. Simply rename the file would cause the desctructor tryiing to remove an non-existent file.

if (abi_path.is_relative()) {
abi_path = data_dir / abi_path;
}

EOS_ASSERT(fc::exists(abi_path) && !fc::is_directory(abi_path), chain::plugin_config_exception, "${path} does not exist or is not a file", ("path", abi_path.generic_string()));
EOS_ASSERT(std::filesystem::exists(abi_path) && !std::filesystem::is_directory(abi_path), chain::plugin_config_exception, "${path} does not exist or is not a file", ("path", abi_path.generic_string()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding a to_variant(fs::path) so we don't need to put generic_string() in all these log/asserts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Although a new logging framework is likely going to make us add fmt::formatter<> for all our types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like to_variant is already provided.

temp_cfile(const char* mode = "wb"){
std::filesystem::path template_path{ std::filesystem::temp_directory_path() / "fc-XXXXXX" };
char tmp_buf[4096];
strncpy(tmp_buf, template_path.c_str(), 4096);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can result in tmp_buf lacking a null terminator.

#include <boost/predef/os.h>
#include <filesystem>

// adapted from boost source boost/dll/detail/posix/program_location_impl.hpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we continue to use boost DLL with BOOST_DLL_USE_STD_FS, so we don't need this local reimplementation?

libraries/libfc/include/fc/io/cfile.hpp Outdated Show resolved Hide resolved
libraries/libfc/include/fc/io/cfile.hpp Show resolved Hide resolved
libraries/libfc/include/fc/io/cfile.hpp Show resolved Hide resolved
@@ -692,7 +690,7 @@ namespace fc { namespace json_relaxed

FC_THROW_EXCEPTION( parse_error_exception, "expected: null|true|false" );
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way you can turn this auto removal of whitespace off in your editor?

plugins/chain_plugin/test/test_trx_retry_db.cpp Outdated Show resolved Hide resolved
@huangminghuang huangminghuang requested a review from heifner April 18, 2023 15:48
@huangminghuang huangminghuang merged commit f3b9214 into main Apr 18, 2023
@huangminghuang huangminghuang deleted the huangminghuang/filesystem branch April 18, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

replace boost::filesystem with std::filesystem
4 participants