From 43f4ba193bd4c9daf7fade6f2887e10232b83dc0 Mon Sep 17 00:00:00 2001 From: xconverge Date: Tue, 24 Jul 2018 18:31:59 -0700 Subject: [PATCH 1/4] Fixes #2799 --- src/util/util.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util/util.ts b/src/util/util.ts index ce79059d387..36c8c4328e5 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -38,5 +38,18 @@ export async function getCursorsAfterSync(timeout: number = 0): Promise } export function getExtensionDirPath(): string { - return path.join(os.homedir(), '.VSCodeVim'); + let homeVar = 'XDG_CACHE_HOME'; + if (process.platform === 'win32') { + homeVar = 'LOCALAPPDATA'; + } + + // Try to find the directory path + let newPath = process.env[homeVar]; + + // If path is not found, fallback to homedir + if (newPath === undefined || newPath === '') { + newPath = os.homedir(); + } + + return path.join(newPath, '.vscodevim'); } From 5bb2e190f5d3dbe04021187ebdd69fb16651dcbd Mon Sep 17 00:00:00 2001 From: xconverge Date: Tue, 24 Jul 2018 20:38:29 -0700 Subject: [PATCH 2/4] Use package to manage cache directory --- package.json | 1 + src/util/util.ts | 17 ++++------------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5087eb467a8..ffc191834f8 100644 --- a/package.json +++ b/package.json @@ -600,6 +600,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "dependencies": { + "appdirectory": "0.1.0", "clipboardy": "1.2.3", "diff-match-patch": "1.0.1", "lodash": "4.17.10", diff --git a/src/util/util.ts b/src/util/util.ts index 36c8c4328e5..8ad87aeb0ca 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -5,6 +5,8 @@ import { Position } from '../common/motion/position'; import { Range } from '../common/motion/range'; import { logger } from './logger'; +const AppDirectory = require('appdirectory'); + /** * This is certainly quite janky! The problem we're trying to solve * is that writing editor.selection = new Position() won't immediately @@ -38,18 +40,7 @@ export async function getCursorsAfterSync(timeout: number = 0): Promise } export function getExtensionDirPath(): string { - let homeVar = 'XDG_CACHE_HOME'; - if (process.platform === 'win32') { - homeVar = 'LOCALAPPDATA'; - } - - // Try to find the directory path - let newPath = process.env[homeVar]; - - // If path is not found, fallback to homedir - if (newPath === undefined || newPath === '') { - newPath = os.homedir(); - } + const dirs = new AppDirectory('VSCodeVim'); - return path.join(newPath, '.vscodevim'); + return dirs.userCache(); } From 30523693e2b02f69ebbc25813f822fdc796b022c Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Tue, 24 Jul 2018 21:14:57 -0700 Subject: [PATCH 3/4] use mkdirp instead of mkdir --- package.json | 1 + src/cmd_line/commandLineHistory.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ffc191834f8..3ec93cb5bf5 100644 --- a/package.json +++ b/package.json @@ -604,6 +604,7 @@ "clipboardy": "1.2.3", "diff-match-patch": "1.0.1", "lodash": "4.17.10", + "mkdirp": "0.5.1", "neovim-client": "2.1.0", "promised-neovim-client": "2.0.2", "untildify": "3.0.3", diff --git a/src/cmd_line/commandLineHistory.ts b/src/cmd_line/commandLineHistory.ts index 308821e4de2..94360a4d6c9 100644 --- a/src/cmd_line/commandLineHistory.ts +++ b/src/cmd_line/commandLineHistory.ts @@ -3,6 +3,8 @@ import * as path from 'path'; import { configuration } from '../configuration/configuration'; import { logger } from '../util/logger'; +const mkdirp = require('mkdirp'); + export class CommandLineHistory { private static readonly _historyFileName = '.cmdline_history'; private _historyDir: string; @@ -59,7 +61,7 @@ export class CommandLineHistory { return new Promise((resolve, reject) => { try { if (!fs.existsSync(this._historyDir)) { - fs.mkdirSync(this._historyDir, 0o775); + mkdirp.sync(this._historyDir, 0o775); } } catch (err) { logger.error( From f95cd84fb4bd418d311d9e2c2396a6687a8c0e09 Mon Sep 17 00:00:00 2001 From: xconverge Date: Tue, 24 Jul 2018 21:26:41 -0700 Subject: [PATCH 4/4] Add cache directory to debug logger --- src/util/util.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/util.ts b/src/util/util.ts index 8ad87aeb0ca..26690f8f387 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -41,6 +41,7 @@ export async function getCursorsAfterSync(timeout: number = 0): Promise export function getExtensionDirPath(): string { const dirs = new AppDirectory('VSCodeVim'); + logger.debug("VSCodeVim Cache Directory: " + dirs.userCache()); return dirs.userCache(); }