Skip to content

Commit

Permalink
fix keychain data paths on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Feb 15, 2019
1 parent 6a1e5ba commit 8531528
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions keychain_lib/include/keychain_lib/keychain_commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
#else

#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
#define KEY_DEFAULT_PATH "./keychain"
#define LOG_DEFAULT_PATH "./keychain/logs"
#define KEY_DEFAULT_PATH "/keychain"
#define LOG_DEFAULT_PATH "/keychain/logs"
#else

#ifdef _WIN32
Expand Down
1 change: 1 addition & 0 deletions keychain_lib/src/keychain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ keychain::keychain()
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto key_dir = bfs::path(getenv("HOME"));
key_dir += "/";
key_dir += bfs::path(KEY_DEFAULT_PATH_);
#else
bfs::path key_dir(KEY_DEFAULT_PATH_);
Expand Down
10 changes: 9 additions & 1 deletion keychain_lib/src/keychain_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@

#include <keychain.hpp>

namespace bfs = boost::filesystem;

logger_singleton::logger_singleton(std::string postfix)
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto dir = bfs::path(getenv("HOME"));
dir += "/";
dir += bfs::path(LOG_DEFAULT_PATH);
#else
bfs::path dir(LOG_DEFAULT_PATH);
#endif

typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
std::string def_log_path = std::string(LOG_DEFAULT_PATH);
std::string def_log_path = dir.c_str();
// Create a text file sink
#ifdef _WIN32
if (getenv("USERPROFILE") != NULL) {
Expand Down
10 changes: 5 additions & 5 deletions keychain_lib/src/keyfile_singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void keyfile_singleton::keydata_load()
"Can not create key directory, path = ${directory}", ("directory", key_dir.string()));
}

auto first = bfs::directory_iterator(bfs::path(KEY_DEFAULT_PATH_));
auto first = bfs::directory_iterator(key_dir);
std::for_each(first, bfs::directory_iterator(), [this](const auto& unit) {
try {
fc_light::variant j_keyfile = open_keyfile(unit.path().c_str());
Expand All @@ -80,7 +80,7 @@ void keyfile_singleton::signlog_load()
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto dir = bfs::path(getenv("HOME"));
key_dir += bfs::path(SIGN_LOGS_DEFAULT_PATH_);
dir += bfs::path(SIGN_LOGS_DEFAULT_PATH_);
#else
bfs::path dir(SIGN_LOGS_DEFAULT_PATH_);
#endif
Expand All @@ -93,7 +93,7 @@ void keyfile_singleton::signlog_load()
"Can not create sign_logs directory, path = ${directory}", ("directory", dir.string()));
}

auto first = bfs::directory_iterator(bfs::path(SIGN_LOGS_DEFAULT_PATH_));
auto first = bfs::directory_iterator(dir);
std::for_each(first, bfs::directory_iterator(), [this](const auto& unit) {
try {
fc_light::variant j_keyfile = open_keyfile(unit.path().c_str());
Expand Down Expand Up @@ -315,11 +315,11 @@ void keyfile_singleton::flush_all() const
bfs::path keyfile_dir(KEY_DEFAULT_PATH_);
#endif
auto first = bfs::directory_iterator(keyfile_dir);
std::for_each(m_keydata_map.begin(), m_keydata_map.end(), [first](const auto& keyfile_data) {
std::for_each(m_keydata_map.begin(), m_keydata_map.end(), [first, &keyfile_dir](const auto& keyfile_data) {
auto hash = dev::openssl::sha3(keyfile_data.keyinfo.public_key);
auto filename = hash.hex().substr(0, 16);
filename += ".json";
bfs::path filepath(std::string(KEY_DEFAULT_PATH_"/") + std::string(filename));
bfs::path filepath = keyfile_dir.c_str() + std::string(filename);
auto fout = std::ofstream(filepath.c_str());
if (!fout.is_open())
FC_LIGHT_THROW_EXCEPTION(fc_light::internal_error_exception, "Cannot open keyfile (${filename})", ("filename", filename));
Expand Down

0 comments on commit 8531528

Please sign in to comment.