From b76c72ef6c311a8fc6d132589626a7e0e4dda3f2 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 29 Aug 2021 19:36:36 +0200 Subject: [PATCH] make the getUsage() function a bit more reliable, and fine-tune the amount of files to delete from static/ --- cacheControl.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cacheControl.js b/cacheControl.js index 09c928b..26362bc 100644 --- a/cacheControl.js +++ b/cacheControl.js @@ -16,7 +16,15 @@ module.exports.removeCacheFiles = function() { return new Promise((resolve, reject) => { let size = spawn('du', ['-sBM', './static/']) size.stdout.on('data', function (data) { - usage = parseInt(data) + data = data.toString() + let lines = data.split('\n') + if(lines) { + for(let i = lines.length; i >= 0; i--) { + if(lines[i] && lines[i].includes('./static/')) { + usage = parseInt(lines[i]) + } + } + } resolve(usage) }) }) @@ -28,10 +36,10 @@ module.exports.removeCacheFiles = function() { if(usage > limit) { const { exec } = require('child_process') exec(`cd ${pics} && ls -1btr -Iflairs -Iicons -Ithumbs -I.gitignore | head -50 | xargs rm -f --`) - exec(`cd ${flairs} && ls -1btr -I.gitignore | head -50 | xargs rm -f --`) - exec(`cd ${icons} && ls -1btr -I.gitignore | head -50 | xargs rm -f --`) - exec(`cd ${thumbs} && ls -1btr -I.gitignore | head -50 | xargs rm -f --`) - exec(`cd ${vids} && ls -1btr -I.gitignore | head -30 | xargs rm -f --`) + exec(`cd ${flairs} && ls -1btr -I.gitignore | head -6 | xargs rm -f --`) + exec(`cd ${icons} && ls -1btr -I.gitignore | head -6 | xargs rm -f --`) + exec(`cd ${thumbs} && ls -1btr -I.gitignore | head -80 | xargs rm -f --`) + exec(`cd ${vids} && ls -1btr -I.gitignore | head -2 | xargs rm -f --`) } resolve(1) })