Поправка механизма чистки TempPublicDir

This commit is contained in:
Book Pauk
2020-11-12 19:39:57 +07:00
parent 355410c03c
commit ae260e74f6
2 changed files with 13 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ module.exports = {
loggingEnabled: true, loggingEnabled: true,
maxUploadFileSize: 50*1024*1024,//50Мб maxUploadFileSize: 50*1024*1024,//50Мб
maxTempPublicDirSize: 512*1024*1024,//512Мб maxTempPublicDirSize: 512*1024*1024,//512Мб + 20% квота если проблема с remoteWebDavStorage
maxUploadPublicDirSize: 200*1024*1024,//100Мб maxUploadPublicDirSize: 200*1024*1024,//100Мб
useExternalBookConverter: false, useExternalBookConverter: false,

View File

@@ -266,30 +266,38 @@ class ReaderWorker {
files.push({name, stat}); files.push({name, stat});
} }
} }
log(`clean dir ${dir}, maxSize=${maxSize}, found ${files.length} files`); log(`clean dir ${dir}, maxSize=${maxSize}, found ${files.length} files, total size=${size}`);
files.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs); files.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs);
let i = 0; let i = 0;
let j = 0;
while (i < files.length && size > maxSize) { while (i < files.length && size > maxSize) {
const file = files[i]; const file = files[i];
const oldFile = `${dir}/${file.name}`; const oldFile = `${dir}/${file.name}`;
let remoteSuccess = true;
//отправляем только this.config.tempPublicDir //отправляем только this.config.tempPublicDir
//TODO: убрать в будущем, т.к. уже делается ленивое сохранение compFilename в удаленном хранилище
if (this.remoteWebDavStorage && dir === this.config.tempPublicDir) { if (this.remoteWebDavStorage && dir === this.config.tempPublicDir) {
remoteSuccess = false;
try { try {
//log(`remoteWebDavStorage.putFile ${path.basename(oldFile)}`); //log(`remoteWebDavStorage.putFile ${path.basename(oldFile)}`);
await this.remoteWebDavStorage.putFile(oldFile); await this.remoteWebDavStorage.putFile(oldFile);
remoteSuccess = true;
} catch (e) { } catch (e) {
log(LM_ERR, e.stack); log(LM_ERR, e.stack);
} }
} }
//реально удаляем только если сохранили в хранилище
if (remoteSuccess || size > maxSize*1.2) {
await fs.remove(oldFile); await fs.remove(oldFile);
j++;
}
size -= file.stat.size; size -= file.stat.size;
i++; i++;
} }
log(`removed ${i} files`); log(`removed ${j} files`);
} catch(e) { } catch(e) {
log(LM_ERR, e.stack); log(LM_ERR, e.stack);
} finally { } finally {