Skip to content
Snippets Groups Projects
Commit afa3413a authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Use the "max_age" and "max_files" values from configuration if not set in base

Work-around for issue #861

This is the utility script for maintaining file bases, if you didn't know. :-)
parent 20c4d22c
No related branches found
No related tags found
No related merge requests found
...@@ -78,8 +78,9 @@ for(var i in dir_list) { ...@@ -78,8 +78,9 @@ for(var i in dir_list) {
} }
log("Removed " + removed + " offline files"); log("Removed " + removed + " offline files");
} }
if(base.max_age) { var max_age = base.max_age || dir.max_age;
log("Purging old files, imposing max age of " + base.max_age + " days"); if(max_age) {
log("Purging old files, imposing max age of " + max_age + " days");
var list = base.get_list(FileBase.DETAIL.NORM, /* sort: */false); var list = base.get_list(FileBase.DETAIL.NORM, /* sort: */false);
var removed = 0; var removed = 0;
for(var j = 0; j < list.length; j++) { for(var j = 0; j < list.length; j++) {
...@@ -94,7 +95,7 @@ for(var i in dir_list) { ...@@ -94,7 +95,7 @@ for(var i in dir_list) {
age_desc = "last downloaded"; age_desc = "last downloaded";
} }
var file_age = Math.floor((now - t) / (24 * 60 * 60)); var file_age = Math.floor((now - t) / (24 * 60 * 60));
if(file_age > base.max_age) { if(file_age > max_age) {
log("Removing " + base.get_path(file.name) + " " + age_desc + " " + file_age + " days ago"); log("Removing " + base.get_path(file.name) + " " + age_desc + " " + file_age + " days ago");
if(options.test) if(options.test)
removed++; removed++;
...@@ -106,13 +107,14 @@ for(var i in dir_list) { ...@@ -106,13 +107,14 @@ for(var i in dir_list) {
} }
} }
} }
log("Removed " + removed + " of " + list.length + " files due to age of " + base.max_age + " days"); log("Removed " + removed + " of " + list.length + " files due to age of " + max_age + " days");
} }
if(base.max_files) { var max_files = base.max_files || dir.max_files;
log("Purging excess files, imposing max files limit of " + base.max_files); if(max_files) {
log("Purging excess files, imposing max files limit of " + max_files);
var list = base.get_list(FileBase.DETAIL.MIN, /* sort: */false); var list = base.get_list(FileBase.DETAIL.MIN, /* sort: */false);
var removed = 0; var removed = 0;
var excess = list.length - base.max_files; var excess = list.length - max_files;
for(var j = 0; j < list.length && removed < excess; j++) { for(var j = 0; j < list.length && removed < excess; j++) {
var file = list[j]; var file = list[j];
if(exclude.indexOf(file.name.toUpperCase()) >= 0) if(exclude.indexOf(file.name.toUpperCase()) >= 0)
...@@ -127,7 +129,7 @@ for(var i in dir_list) { ...@@ -127,7 +129,7 @@ for(var i in dir_list) {
removed++; removed++;
} }
} }
log("Removed " + removed + " of " + list.length + " files due to max file limit of " + base.max_files); log("Removed " + removed + " of " + list.length + " files due to max file limit of " + max_files);
} }
base.close(); base.close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment