Skip to content

Commit

Permalink
20253: Fixes issues storing files (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored May 9, 2024
1 parent db5fc3b commit f649820
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/Amalgam/importexport/FileSupportJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,20 @@ EvaluableNode *EvaluableNodeJSONTranslation::Load(const std::string &resource_pa
// Save node tree to disk as JSON.
bool EvaluableNodeJSONTranslation::Store(EvaluableNode *code, const std::string &resource_path, EvaluableNodeManager *enm, bool sort_keys)
{
std::string error_string;
if(!Platform_IsResourcePathAccessible(resource_path, false, error_string))
{
std::cerr << "Error storing JSON to " << resource_path + ": " << error_string << std::endl;
return false;
}

auto [result, converted] = EvaluableNodeToJson(code, sort_keys);
if(!converted)
{
std::cerr << "Error storing JSON: cannot convert node to JSON" << std::endl;
return false;
}

std::ofstream file(resource_path);
if(!file.good())
{
std::cerr << "Error storing JSON: cannot write to file " + resource_path << std::endl;
return false;
}

file << result;

return true;
Expand Down
13 changes: 6 additions & 7 deletions src/Amalgam/importexport/FileSupportYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,19 @@ EvaluableNode *EvaluableNodeYAMLTranslation::Load(const std::string &resource_pa

bool EvaluableNodeYAMLTranslation::Store(EvaluableNode *code, const std::string &resource_path, EvaluableNodeManager *enm, bool sort_keys)
{
std::string error_string;
if(!Platform_IsResourcePathAccessible(resource_path, false, error_string))
{
std::cerr << "Error storing YAML to " + resource_path + ": " << error_string << std::endl;
return false;
}

auto [result, converted] = EvaluableNodeToYaml(code, sort_keys);
if(!converted)
{
std::cerr << "Error storing YAML: cannot convert node to YAML" << std::endl;
return false;
}

std::ofstream file(resource_path);
if(!file.good())
{
std::cerr << "Error storing JSON: cannot write to file " + resource_path << std::endl;
return false;
}
file << result;

return true;
Expand Down

0 comments on commit f649820

Please sign in to comment.