Skip to content

Commit

Permalink
fix path to key_data on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Feb 14, 2019
1 parent 79ba94a commit 3f8049b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 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 "/var/keychain"
#define LOG_DEFAULT_PATH "/var/keychain/logs"
#define KEY_DEFAULT_PATH "./keychain"
#define LOG_DEFAULT_PATH "./keychain/logs"
#else

#ifdef _WIN32
Expand Down
5 changes: 5 additions & 0 deletions keychain_lib/src/keychain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ keychain::keychain()
: keychain_base(),
m_init_path(bfs::current_path())
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto key_dir = bfs::path(getenv("HOME"));
key_dir += bfs::path(KEY_DEFAULT_PATH_);
#else
bfs::path key_dir(KEY_DEFAULT_PATH_);
#endif

if(!bfs::exists(key_dir))
{
Expand Down
38 changes: 31 additions & 7 deletions keychain_lib/src/keyfile_singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ const keyfile_singleton::key_random_access_index_type& keyfile_singleton::random

void keyfile_singleton::keydata_load()
{
// auto curdir = bfs::current_path();

#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto key_dir = bfs::path(getenv("HOME"));
key_dir += bfs::path(KEY_DEFAULT_PATH_);
#else
bfs::path key_dir(KEY_DEFAULT_PATH_);
#endif

if(!bfs::exists(key_dir))
{
Expand Down Expand Up @@ -75,8 +78,12 @@ void keyfile_singleton::keydata_load()

void keyfile_singleton::signlog_load()
{
// auto curdir = bfs::current_path();
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto dir = bfs::path(getenv("HOME"));
key_dir += bfs::path(SIGN_LOGS_DEFAULT_PATH_);
#else
bfs::path dir(SIGN_LOGS_DEFAULT_PATH_);
#endif

if(!bfs::exists(dir))
{
Expand Down Expand Up @@ -254,10 +261,16 @@ void keyfile_singleton::flush_keyfile(const keyfile_singleton::prim_key_type& ke

void keyfile_singleton::flush_keyfile_impl(const value_t& keyfile_data) const
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto filepath = bfs::path(getenv("HOME"));
filepath += bfs::path(KEY_DEFAULT_PATH_"/");
#else
bfs::path filepath(KEY_DEFAULT_PATH_"/");
#endif
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));
filepath += bfs::path(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 All @@ -274,13 +287,19 @@ void keyfile_singleton::flush_logrecords(const prim_key_type& key) const

void keyfile_singleton::flush_logrecords_impl(const prim_key_type& key, const log_records_t& log_records) const
{
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto filepath = bfs::path(getenv("HOME"));
filepath += bfs::path(KEY_DEFAULT_PATH_"/");
#else
bfs::path filepath(KEY_DEFAULT_PATH_"/");
#endif
keyfile_format::signlog_file_t logfile;
logfile.public_key = key;
std::copy(log_records.begin(), log_records.end(), std::back_inserter(logfile.sign_events));
auto hash = dev::openssl::sha3(key);
auto filename = hash.hex().substr(0, 16);
filename += "_signlog.json";
bfs::path filepath(std::string(SIGN_LOGS_DEFAULT_PATH_"/") + std::string(filename));
filepath += 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 All @@ -289,8 +308,13 @@ void keyfile_singleton::flush_logrecords_impl(const prim_key_type& key, const lo

void keyfile_singleton::flush_all() const
{
auto curdir = bfs::current_path();
auto first = bfs::directory_iterator(bfs::path(KEY_DEFAULT_PATH_));
#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
auto keyfile_dir = bfs::path(getenv("HOME"));
keyfile_dir += bfs::path(KEY_DEFAULT_PATH_);
#else
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) {
auto hash = dev::openssl::sha3(keyfile_data.keyinfo.public_key);
auto filename = hash.hex().substr(0, 16);
Expand Down

0 comments on commit 3f8049b

Please sign in to comment.