Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unique temp directories and clean up afterwards #370

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions app/main-process/inklecate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const child_process = require('child_process');
const spawn = child_process.spawn;
const fs = require('fs');
const os = require('os');
const path = require("path");
const electron = require('electron');
const ipc = electron.ipcMain;
const mkdirp = require('mkdirp');
const del = require('del');

// inklecate is packaged outside of the main asar bundle since it's executable
const inklecateNames = {
Expand All @@ -24,16 +26,35 @@ catch(e) {
}

var tempInkPath;
if (process.platform == "darwin" || process.platform == "linux") {
tempInkPath = process.env.TMPDIR ? path.join(process.env.TMPDIR, "inky_compile") : "/tmp/inky_compile";
} else {
tempInkPath = path.join(process.env.temp, "inky_compile")

function setUp() {
const tmpDir = os.tmpdir();
fs.mkdtemp(`${tmpDir}${path.sep}inky_compile_`, (err, folder) => {
if (err) {
throw new Error(err);
}

tempInkPath = folder;
})
}

function tearDown() {
if (tempInkPath) {
try {
del.sync(tempInkPath, {force: true});
} catch (err) {
console.error(`Failed to delete temporary directory ${tempInkPath}: ${err}`);
}
}
}

var sessions = {};


function compile(compileInstruction, requester) {
if (!tempInkPath) {
throw new Error("Temporary directory not initialized");
}

var sessionId = compileInstruction.sessionId;

Expand Down Expand Up @@ -354,5 +375,7 @@ ipc.on("get-runtime-path-in-source", (event, runtimePath, sessionId) => {


exports.Inklecate = {
killSessions: killSessions
setUp,
tearDown,
killSessions
}
4 changes: 4 additions & 0 deletions app/main-process/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ app.on('before-quit', function () {
// We need this to differentiate between pressing quit (which should quit) or closing all windows
// (which leaves the app open)
isQuitting = true;

Inklecate.tearDown();
});

ipc.on("project-cancelled-close", (event) => {
Expand All @@ -47,6 +49,8 @@ ipc.on("project-cancelled-close", (event) => {
// Some APIs can only be used after this event occurs.
app.on('ready', function () {

Inklecate.setUp();

app.on('window-all-closed', function () {
if (process.platform != 'darwin' || isQuitting) {
app.quit();
Expand Down
Loading