From e747b5740d8ee3752da3daf27ccb2c220314a6ae Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 31 Dec 2019 17:39:36 +0100 Subject: changes: Better cleanup in diff --- modules/changes/changes.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/changes/changes.js b/modules/changes/changes.js index d4c48e2..302628b 100644 --- a/modules/changes/changes.js +++ b/modules/changes/changes.js @@ -435,9 +435,17 @@ module.exports=function(app,io,_moddir){ res.send(); return; } + function cleanup() { + try { fs.unlinkSync(folder+"/old.html"); } catch(e) { console.log(e); } + try { fs.unlinkSync(folder+"/new.html"); } catch(e) { console.log(e); } + try { fs.unlinkSync(folder+"/diff.txt"); } catch(e) { console.log(e); } + try { fs.rmdirSync(folder); } catch(e) { console.log(e); } + } + var counter=0; var fscb=function(err){ if(err){ + cleanup(); console.log(err); res.status(500); res.send(); @@ -454,12 +462,7 @@ module.exports=function(app,io,_moddir){ proc.on("exit",function(code,signal){ var stream=fs.createReadStream(folder+"/diff.txt"); stream.pipe(res); - stream.on("end",function(){ - fs.unlinkSync(folder+"/old.html"); - fs.unlinkSync(folder+"/new.html"); - fs.unlinkSync(folder+"/diff.txt"); - fs.rmdirSync(folder); - }); + stream.on("end",cleanup); }); }; fs.writeFile(folder+"/old.html",tl[oldi][2],fscb); -- cgit v1.2.3-70-g09d2