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

Set permissions to config.json file after creating #1621

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions nano/lib/jsonconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
#include <nano/lib/errors.hpp>
#include <nano/lib/utility.hpp>

namespace nano
{
Expand Down Expand Up @@ -118,16 +119,19 @@ class jsonconfig : public nano::error_aware<>
boost::property_tree::read_json (stream_a, tree);
}

/** Open confiruation file, create if necessary */
/** Open configuration file, create if necessary */
void open_or_create (std::fstream & stream_a, std::string const & path_a)
{
stream_a.open (path_a, std::ios_base::in);
if (stream_a.fail ())
if (!boost::filesystem::exists (path_a))
{
stream_a.open (path_a, std::ios_base::out);
// Create temp stream to first create the file
std::ofstream stream (path_a);

// Set permissions before opening otherwise Windows only has read permissions
nano::set_secure_perm_file (path_a);
}
stream_a.close ();
stream_a.open (path_a, std::ios_base::in | std::ios_base::out);

stream_a.open (path_a);
}

/** Returns the boost property node managed by this instance */
Expand Down