From 665c6e07543b06a7c46be9777f16eacadc5ce9cc Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Thu, 24 May 2018 14:41:10 -0700 Subject: [PATCH] fix: ensure client directory is not a file --- src/commands/update.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/commands/update.ts b/src/commands/update.ts index d29af152..2123d369 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -66,6 +66,7 @@ export default class UpdateCommand extends Command { const [num, suffix] = require('filesize')(n, {output: 'array'}) return num.toFixed(1) + ` ${suffix}` } + await this.ensureClientDir() const output = path.join(this.clientRoot, version) const {response: stream} = await http.stream(manifest.gz) @@ -220,4 +221,17 @@ ${binPathEnvVar}="\$DIR/${bin}" ${redirectedEnvVar}=1 "$DIR/../${version}/bin/${ await fs.symlink(`./${version}`, path.join(this.clientRoot, 'current')) } } + + private async ensureClientDir() { + try { + await fs.mkdirp(this.clientRoot) + } catch (err) { + if (err.code === 'EEXIST') { + // for some reason the client directory is sometimes a file + // if so, this happens. Delete it and recreate + await fs.remove(this.clientRoot) + await fs.mkdirp(this.clientRoot) + } else { throw err } + } + } }