try fixing issue number 17 (not done)

pull/664/head
Jeff Becker 5 years ago
parent 37aed7a664
commit e265661adb
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -219,12 +219,6 @@ if(JEMALLOC)
endif(JEMALLOC)
# FS_LIB should resolve to nothing on all other platforms
# it is only required on win32 -rick
set(LIBS ${MALLOC_LIB} ${FS_LIB})
if(NOT WIN32)
set(LIBS ${LIBS} uv)
endif()
if(ANDROID)
list(APPEND LIBS log)
@ -256,6 +250,11 @@ if(NOT WIN32)
add_subdirectory(vendor)
endif()
set(LIBS ${MALLOC_LIB} ${FS_LIB})
if(NOT WIN32)
set(LIBS ${LIBS} uv)
endif()
add_subdirectory(crypto)
add_subdirectory(libutp)
add_subdirectory(llarp)
@ -263,7 +262,7 @@ add_subdirectory(libabyss)
if (NOT WIN32)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS})
elseif(NOT MSVC_VERSION)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
@ -315,7 +314,7 @@ else()
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${EXE} PRIVATE /usr/local/lib)
endif()
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS})
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS})
if(ANDROID)
add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp)

@ -19,8 +19,11 @@ else()
message(FATAL_ERROR "Your operating system is not supported yet")
endif()
set(EXE_LIBS ${STATIC_LIB} cppbackport libutp)
set(FS_LIB stdc++fs)
set(EXE_LIBS ${STATIC_LIB} libutp)
if(RELEASE_MOTTO)
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
endif()

@ -95,7 +95,7 @@ else()
endif(WIN32)
add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC})
target_link_libraries(${PLATFORM_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${UTIL_LIB} libutp Threads::Threads)
target_link_libraries(${PLATFORM_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${UTIL_LIB} libutp Threads::Threads ${LIBS})
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(NON_PC_TARGET)
@ -241,7 +241,7 @@ endif()
add_library(${STATIC_LIB} STATIC ${LIB_SRC})
set(LIBS ${LIBS} libutp)
target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS})
target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB})
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_include_directories(${PLATFORM_LIB} SYSTEM PUBLIC /usr/local/include)

@ -1 +1,34 @@
#include <util/fs.hpp>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <system_error>
namespace llarp
{
namespace util
{
error_code_t
EnsurePrivateFile(fs::path pathname)
{
auto str = pathname.string();
error_code_t ec;
if(fs::exists(pathname, ec)) // file exists
{
fs::permissions(pathname, ~fs::perms::group_all | ~fs::perms::others_all | fs::perms::owner_read | fs::perms::owner_write, ec);
}
else if(!ec) // file is not there
{
int fd = ::open(str.c_str(), O_WRONLY | O_CREAT, 0600);
int e = errno;
if(fd != -1)
{
::close(fd);
}
ec = std::error_code(e, std::generic_category());
errno = 0;
}
return ec;
}
}
}

@ -8,13 +8,9 @@
#define PATH_SEP "/"
#endif
#ifdef _WIN32
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#include "filesystem.h"
namespace fs = cpp17::filesystem;
#endif
#ifndef _MSC_VER
#include <dirent.h>
@ -24,6 +20,28 @@ namespace llarp
{
namespace util
{
using error_code_t = std::error_code;
/// Ensure that a file exists and has correct permissions
/// return any error code or success
error_code_t
EnsurePrivateFile(fs::path pathname);
/// open a stream to a file and ensure it exists before open
/// sets any permissions on creation
template<typename T>
T OpenFileStream(fs::path pathname)
{
T stream;
if(EnsurePrivateFile(pathname))
{
std::string f = pathname.string();
stream.open(f);
}
return stream;
}
using PathVisitor = std::function< bool(const fs::path &) >;
using PathIter = std::function< void(const fs::path &, PathVisitor) >;

Loading…
Cancel
Save