Commit b3a2fbf1 authored by Morag Jean Williams's avatar Morag Jean Williams
Browse files

Merge branch 'fix_deny_overwrite' into 'master'

Core: protect detectors_file_updated by deny_overwrite

See merge request !185
parents c69093c2 eb5c8733
Pipeline #1182853 passed with stages
in 64 minutes and 26 seconds
...@@ -710,11 +710,19 @@ void ModuleManager::finaliseAll() { ...@@ -710,11 +710,19 @@ void ModuleManager::finaliseAll() {
// Write out update detectors file: // Write out update detectors file:
if(global_config.has("detectors_file_updated")) { if(global_config.has("detectors_file_updated")) {
std::string file_name = global_config.getPath("detectors_file_updated"); std::string path = global_config.getPath("detectors_file_updated");
// Check if the file exists // Check if the file exists
std::ofstream file(file_name); if(corryvreckan::path_is_file(path)) {
if(global_config.get<bool>("deny_overwrite", false)) {
throw RuntimeError("Overwriting of existing detectors file " + path + " denied");
}
LOG(WARNING) << "Detectors file " << path << " exists and will be overwritten.";
corryvreckan::remove_file(path);
}
std::ofstream file(path);
if(!file) { if(!file) {
throw ConfigFileUnavailableError(file_name); throw RuntimeError("Cannot create detectors file " + path);
} }
ConfigReader final_detectors; ConfigReader final_detectors;
...@@ -723,7 +731,7 @@ void ModuleManager::finaliseAll() { ...@@ -723,7 +731,7 @@ void ModuleManager::finaliseAll() {
} }
final_detectors.write(file); final_detectors.write(file);
LOG(STATUS) << "Wrote updated detector configuration to " << file_name; LOG(STATUS) << "Wrote updated detector configuration to " << path;
} }
// Check the timing for all events // Check the timing for all events
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment