Skip to content

Commit

Permalink
Set permissions to config.json file after creating (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule committed Jan 23, 2019
1 parent 2e063ec commit 0757cc9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nano/lib/jsonconfig.hpp
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

0 comments on commit 0757cc9

Please sign in to comment.