Keep a maximum of 100 upload files, so we don't fill disk (fixes bug #5900)
This commit is contained in:
parent
287174987c
commit
08c955e107
3 changed files with 11 additions and 4 deletions
|
@ -627,7 +627,7 @@ time_t file_create_time(const std::string& fname)
|
|||
}
|
||||
|
||||
//return the next ordered full filename within this directory
|
||||
std::string next_filename(const std::string &dirname)
|
||||
std::string next_filename(const std::string &dirname, unsigned int max)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::stringstream fname;
|
||||
|
@ -648,6 +648,13 @@ std::string next_filename(const std::string &dirname)
|
|||
}
|
||||
}
|
||||
|
||||
// Erase oldest files if we have too many
|
||||
if (max) {
|
||||
for (unsigned int j = 0; j + max < files.size(); j++) {
|
||||
delete_directory(dirname + "/" + files[j]);
|
||||
}
|
||||
}
|
||||
|
||||
fname << std::setw(8) << std::setfill('0') << num;
|
||||
return dirname + "/" + fname.str();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ bool file_exists(const std::string& name);
|
|||
time_t file_create_time(const std::string& fname);
|
||||
|
||||
//return the next ordered full filename within this directory
|
||||
std::string next_filename(const std::string &dirname);
|
||||
std::string next_filename(const std::string &dirname, unsigned int max = 0);
|
||||
|
||||
struct file_tree_checksum
|
||||
{
|
||||
|
|
|
@ -114,7 +114,7 @@ static int upload_logs(void *_ti)
|
|||
// Currently only enabled when playing campaigns.
|
||||
upload_log::upload_log(bool enable) : game_(NULL), enabled_(enable)
|
||||
{
|
||||
filename_ = next_filename(get_upload_dir());
|
||||
filename_ = next_filename(get_upload_dir(), 100);
|
||||
if (preferences::upload_log() && !thread_.t) {
|
||||
// Thread can outlive us; it uploads everything up to the next
|
||||
// filename, and unsets thread_.t when it's finished.
|
||||
|
@ -140,7 +140,7 @@ upload_log::~upload_log()
|
|||
|
||||
// Try to upload latest log before exit.
|
||||
if (preferences::upload_log() && !thread_.t) {
|
||||
thread_.lastfile = next_filename(get_upload_dir());
|
||||
thread_.lastfile = next_filename(get_upload_dir(), 1000);
|
||||
thread_.t = new threading::thread(upload_logs, &thread_);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue