diff --git a/CMakeLists.txt b/CMakeLists.txt index e2a623f..39ab4cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,8 @@ add_subdirectory(vendor) #/libssh2-1.4.2) setup_library( fc SOURCES ${sources} ) -setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ${Boost_DATE_TIME_LIBRARY}) -setup_executable( ssh_test SOURCES tests/ssh.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ssh2 ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${ZLIB_LIBRARY} ${ALL_OPENSSL_LIBRARIES} ${Boost_DATE_TIME_LIBRARY}) +#setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ${Boost_DATE_TIME_LIBRARY}) +#setup_executable( ssh_test SOURCES tests/ssh.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ssh2 ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${ZLIB_LIBRARY} ${ALL_OPENSSL_LIBRARIES} ${Boost_DATE_TIME_LIBRARY}) #add_executable( test_vec tests/vector_test.cpp ) #target_link_libraries( test_vec fc ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ) diff --git a/include/fc/datastream.hpp b/include/fc/datastream.hpp index 7947bf5..c003982 100644 --- a/include/fc/datastream.hpp +++ b/include/fc/datastream.hpp @@ -21,7 +21,7 @@ struct datastream { inline void skip( size_t s ){ m_pos += s; } inline bool read( char* d, size_t s ) { - if( m_end - m_pos >= (size_t)s ) { + if( size_t(m_end - m_pos) >= (size_t)s ) { memcpy( d, m_pos, s ); m_pos += s; return true; diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index c04a242..d490d44 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -39,6 +39,8 @@ namespace fc { fc::path parent_path()const; fc::string string()const; fc::string generic_string()const; + bool is_relative()const; + bool is_absolute()const; private: fwd _p; }; diff --git a/include/fc/ip.hpp b/include/fc/ip.hpp index 10e53dc..ea64ed1 100644 --- a/include/fc/ip.hpp +++ b/include/fc/ip.hpp @@ -35,7 +35,6 @@ namespace fc { friend bool operator==( const endpoint& a, const endpoint& b ); private: - address _ip; /** * The compiler pads endpoint to a full 8 bytes, so while * a port number is limited in range to 16 bits, we specify @@ -44,6 +43,7 @@ namespace fc { * where they are stored. */ uint32_t _port; + address _ip; }; } class value; diff --git a/include/fc/process.hpp b/include/fc/process.hpp index dfaa6e8..4a596a7 100644 --- a/include/fc/process.hpp +++ b/include/fc/process.hpp @@ -9,6 +9,8 @@ namespace fc { class path; template class vector; + fc::path find_executable_in_path( const fc::string name ); + /** * @brief start and manage an external process * @@ -23,6 +25,7 @@ namespace fc { open_stderr = 0x04, open_all = open_stdin|open_stdout|open_stderr, }; + /** * Return a new process executing the specified exe with the specified args. */ diff --git a/src/error_report.cpp b/src/error_report.cpp index 9095752..59a0c36 100644 --- a/src/error_report.cpp +++ b/src/error_report.cpp @@ -139,7 +139,7 @@ fc::string error_report::to_string()const { } fc::string error_report::to_detail_string()const { fc::stringstream ss; - for( int i = 0; i < stack.size(); ++i ) { + for( uint32_t i = 0; i < stack.size(); ++i ) { ss << stack[i].to_detail_string() << "\n"; } return ss.str(); diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 23835fd..05c90d1 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -81,6 +81,8 @@ namespace fc { fc::path path::parent_path()const { return _p->parent_path(); } + bool path::is_relative()const { return _p->is_relative(); } + bool path::is_absolute()const { return _p->is_absolute(); } directory_iterator::directory_iterator( const fc::path& p ) :_p(p){} @@ -119,7 +121,13 @@ namespace fc { bool exists( const path& p ) { return boost::filesystem::exists(p); } - void create_directories( const path& p ) { boost::filesystem::create_directories(p); } + void create_directories( const path& p ) { + try { + boost::filesystem::create_directories(p); + } catch ( ... ) { + FC_THROW_REPORT( "Unable to create directories ${path}", fc::value().set("path", p ).set("inner", fc::except_str() ) ); + } + } bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); } bool is_regular_file( const path& p ) { return boost::filesystem::is_regular_file(p); } uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); } diff --git a/src/process.cpp b/src/process.cpp index 1b5db40..4a79311 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -4,14 +4,29 @@ #include #include #include -#include +#include +#include +#include #include +#include namespace fc { - namespace bp = boost::process; namespace io = boost::iostreams; + fc::path find_executable_in_path( const fc::string name ) { + try { + return fc::string(bp::find_executable_in_path( std::string(name), "" )); + } catch (...) { + const char* p = std::getenv("PATH"); + FC_THROW_REPORT( "Unable to find executable ${exe} in path.", + fc::value().set("exe", name) + .set("inner", fc::except_str() ) + .set("PATH", fc::string(p!=nullptr?p:"") ) ); + } + return fc::path(); + } + class process_sink : public io::sink { public: struct category : io::sink::category, io::flushable_tag {};