From 673b0dcd96c7f964267c100ca3eb65ecffa019c4 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sat, 3 Dec 2016 14:11:16 +0100 Subject: [PATCH] Don't deploy homedir, downloads or desktop This closes #99 --- bin/now-deploy.js | 4 ++++ lib/utils/check-path.js | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 lib/utils/check-path.js diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 56918dd..de9c3f8 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -23,6 +23,7 @@ import promptOptions from '../lib/utils/prompt-options' import {handleError, error} from '../lib/error' import {fromGit, isRepoPath, gitPathParts} from '../lib/git' import readMetaData from '../lib/read-metadata' +import checkPath from '../lib/utils/check-path' const argv = minimist(process.argv.slice(2), { string: [ @@ -250,6 +251,9 @@ async function sync(token) { } } + // Make sure that directory is not too big + await checkPath(path) + if (!quiet) { if (gitRepo.main) { const gitRef = gitRepo.ref ? ` at "${chalk.bold(gitRepo.ref)}" ` : '' diff --git a/lib/utils/check-path.js b/lib/utils/check-path.js new file mode 100644 index 0000000..055abe9 --- /dev/null +++ b/lib/utils/check-path.js @@ -0,0 +1,47 @@ +// Native +import os from 'os' +import path from 'path' + +// Ours +import {error} from '../error' + +export default async dir => { + if (!dir) { + return + } + + const home = os.homedir() + let location + + const paths = { + home, + desktop: path.join(home, 'Desktop'), + downloads: path.join(home, 'Downloads') + } + + for (const locationPath in paths) { + if (!{}.hasOwnProperty.call(paths, locationPath)) { + continue + } + + if (dir === paths[locationPath]) { + location = locationPath + } + } + + let locationName + + switch (location) { + case 'home': + locationName = 'user directory' + break + case 'downloads': + locationName = 'downloads directory' + break + default: + locationName = location + } + + error(`You're trying to deploy your ${locationName}.`) + process.exit(1) +}