From c92d4dfb37ba49791b17cd64645abec68d1b58f5 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sat, 26 Nov 2016 12:28:32 +0100 Subject: [PATCH] Clean up tmp dir for repo in a better way --- bin/now-deploy.js | 9 +++++++-- lib/github.js | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index feb4a57..86f3d3b 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -229,8 +229,12 @@ async function sync(token) { } if (repo) { + // Tell now which directory to deploy path = repo.path - gitHubRepo = true + + // Set global variable for deleting tmp dir later + // once the deployment has finished + gitHubRepo = repo } else if (isRepoPath(rawPath)) { stopDeployment(`This path neither exists, nor is there a repository named "${rawPath}" on GitHub`) } else { @@ -529,7 +533,8 @@ function printLogs(host) { } if (gitHubRepo) { - fs.removeSync(path) + // Delete temporary directory that contains repository + gitHubRepo.cleanup() if (debug) { console.log(`> [debug] Removed temporary repo directory`) diff --git a/lib/github.js b/lib/github.js index 780c0a6..c8db1fb 100644 --- a/lib/github.js +++ b/lib/github.js @@ -35,7 +35,10 @@ const downloadRepo = async repoPath => { const url = `https://api.github.com/repos/${repoPath}/tarball` const tmpDir = await tmp.dir({ - keep: true + // We'll remove it manually once deployment is done + keep: true, + // Recursively remove directory when calling respective method + unsafeCleanup: true }) await download(url, tmpDir.path, {