From db1ae27fb2b4ce1518d93115a700f234aff8ed2d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 4 Nov 2017 21:10:06 +0100 Subject: [PATCH] More unique temporary directory (Closes #568) --- app/common/constants.js | 5 +++++ app/network/network.js | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/common/constants.js b/app/common/constants.js index 30969fd59..7ff84df05 100644 --- a/app/common/constants.js +++ b/app/common/constants.js @@ -24,6 +24,11 @@ export function getAppEnvironment () { return process.env.INSOMNIA_ENV || 'production'; } +export function getTempDir () { + // NOTE: Using a fairly unique name here because "insomnia" is a common word + return path.join(electron.remote.app.getPath('temp'), `insomnia_${getAppVersion()}`); +} + export function isMac () { return getAppPlatform() === 'darwin'; } diff --git a/app/network/network.js b/app/network/network.js index 4f8193a18..2116d9160 100644 --- a/app/network/network.js +++ b/app/network/network.js @@ -5,8 +5,6 @@ import type {Workspace} from '../models/workspace'; import type {Settings} from '../models/settings'; import type {RenderedRequest} from '../common/render'; import {getRenderContext, getRenderedRequest} from '../common/render'; - -import electron from 'electron'; import mkdirp from 'mkdirp'; import clone from 'clone'; import {parse as urlParse, resolve as urlResolve} from 'url'; @@ -15,7 +13,7 @@ import {join as pathJoin} from 'path'; import * as models from '../models'; import * as querystring from '../common/querystring'; import * as util from '../common/misc.js'; -import {AUTH_AWS_IAM, AUTH_BASIC, AUTH_DIGEST, AUTH_NETRC, AUTH_NTLM, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED, getAppVersion, STATUS_CODE_PLUGIN_ERROR} from '../common/constants'; +import {AUTH_AWS_IAM, AUTH_BASIC, AUTH_DIGEST, AUTH_NETRC, AUTH_NTLM, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED, getAppVersion, getTempDir, STATUS_CODE_PLUGIN_ERROR} from '../common/constants'; import {describeByteSize, getContentTypeHeader, hasAuthHeader, hasContentTypeHeader, hasUserAgentHeader, setDefaultProtocol} from '../common/misc'; import fs from 'fs'; import * as db from '../common/database'; @@ -257,7 +255,7 @@ export function _actuallySend ( // Setup CA Root Certificates if not on Mac. Thanks to libcurl, Mac will use // certificates form the OS. if (process.platform !== 'darwin') { - const basCAPath = pathJoin(electron.remote.app.getPath('temp'), 'insomnia'); + const basCAPath = getTempDir(); const fullCAPath = pathJoin(basCAPath, CACerts.filename); try { @@ -348,7 +346,7 @@ export function _actuallySend ( // Certificate file now found! // LEGACY: Certs used to be stored in blobs (not as paths), so lets write it to // the temp directory first. - const fullBase = pathJoin(electron.remote.app.getPath('temp'), 'insomnia'); + const fullBase = getTempDir(); mkdirp.sync(fullBase); const name = `${renderedRequest._id}_${renderedRequest.modified}`;