Skip to content

Commit

Permalink
fix: ensure client directory is not a file
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed May 24, 2018
1 parent ac3ed8b commit 665c6e0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
}
}
}

0 comments on commit 665c6e0

Please sign in to comment.