Skip to content

Commit

Permalink
campaignd: Refactor config commit boilerplate into a separate method
Browse files Browse the repository at this point in the history
(Backported ada5a7c from master.)
  • Loading branch information
irydacea committed Oct 10, 2014
1 parent df6aad4 commit 6df2cfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -195,8 +195,7 @@ server::server(const std::string& cfg_file, size_t min_threads, size_t max_threa
server::~server()
{
delete input_;
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);
write_config();
}

int server::load_config()
Expand Down Expand Up @@ -262,6 +261,12 @@ void server::load_blacklist()
}
}

void server::write_config()
{
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);
}

void server::fire(const std::string& hook, const std::string& addon)
{
const std::map<std::string, std::string>::const_iterator itor = hooks_.find(hook);
Expand Down Expand Up @@ -370,8 +375,7 @@ void server::run()
}
//write config to disk every ten minutes
if((increment%(60*10*50)) == 0) {
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);
write_config();
}

network::process_send_queue();
Expand Down Expand Up @@ -629,8 +633,9 @@ void server::run()

(*campaign)["size"] = lexical_cast<std::string>(
file_size(filename));
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);

write_config();

network::send_data(construct_message(message), sock);

fire("hook_post_upload", upload["name"]);
Expand Down Expand Up @@ -672,8 +677,9 @@ void server::run()
break;
}
}
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);

write_config();

network::send_data(construct_message("Add-on deleted."), sock);

fire("hook_post_erase", erase["name"]);
Expand All @@ -695,8 +701,9 @@ void server::run()
network::send_data(construct_error("No new passphrase was supplied."), sock);
} else {
campaign["passphrase"] = cpass["new_passphrase"];
scoped_ostream out = ostream_file(cfg_file_);
write(*out, cfg_);

write_config();

network::send_data(construct_message("Passphrase changed."), sock);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/campaign_server/campaign_server.hpp
Expand Up @@ -63,6 +63,11 @@ class server : private boost::noncopyable
*/
int load_config();

/**
* Writes the server configuration WML back to disk.
*/
void write_config();

/**
* Reads the add-ons upload blacklist from WML.
*/
Expand Down

0 comments on commit 6df2cfd

Please sign in to comment.