From 31cfc45e586253bc286561a64648d150e0b66d71 Mon Sep 17 00:00:00 2001 From: jake87 Date: Wed, 17 Nov 2021 21:16:22 +1100 Subject: [PATCH] Fix null processing ( again ) --- packages/ctl/ctl.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/ctl/ctl.js b/packages/ctl/ctl.js index 6fccc9b1..fd124e94 100755 --- a/packages/ctl/ctl.js +++ b/packages/ctl/ctl.js @@ -160,7 +160,6 @@ masterConfigCommands.add(new libCommand.Command({ let emmiter = new events.EventEmitter(); editorSpawn.on("exit", async (exit) => { const data = await fs.readFile(tmpFile, "utf8"); - let final = []; let splitData = data.split(/\r?\n/); // split on newlines let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a); @@ -173,23 +172,15 @@ masterConfigCommands.add(new libCommand.Command({ let part = ""; try { part = filtered[index][1].trim(); + // it's a string if we can read it } catch (err) { + // if we can't read it, it's a empty field and therefor null part = ""; } - if (part === "null") { - print(`Warning: ${finalIndex} has been set to the value null, not the string "null".`); - part = ""; - } - final[finalIndex] = part; - // trim whitespace and put in final array for processing - } - } - for (let element in final) { - if (element in final) { try { await libLink.messages.setMasterConfigField.send(control, { - field: element, - value: final[element], + field: finalIndex, + value: part, }); } catch (err) { // eslint-disable-next-line @@ -200,7 +191,14 @@ masterConfigCommands.add(new libCommand.Command({ emmiter.emit("dot_on_done"); }); await events.once(emmiter, "dot_on_done"); - await fs.unlink(tmpFile); + await fs.unlink(tmpFile, (err) => { + if (err) { + print("err: temporary file", tmpFile, "could not be deleted."); + print("This is not fatal, but they may build up over time if the issue persists."); + print("Trace:"); + print(err); + } + }); }, }));