From 39ab73ff6140457bf5646ea5d5e73b128bae46e7 Mon Sep 17 00:00:00 2001 From: Brandon Freitag Date: Mon, 25 Jan 2016 01:48:06 -0800 Subject: [PATCH] Check that source exists for hard links --- src/ln.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ln.js b/src/ln.js index 9b91af5..ac2fd8d 100644 --- a/src/ln.js +++ b/src/ln.js @@ -33,10 +33,6 @@ function _ln(options, source, dest) { var isAbsolute = (path.resolve(source) === sourcePath); dest = path.resolve(process.cwd(), String(dest)); - if ((isAbsolute && !fs.existsSync(sourcePath)) || !fs.existsSync(path.resolve(process.cwd(), path.dirname(dest), source))) { - common.error('Source file does not exist', true); - } - if (fs.existsSync(dest)) { if (!options.force) { common.error('Destination file exists', true); @@ -46,8 +42,14 @@ function _ln(options, source, dest) { } if (options.symlink) { + if ((isAbsolute && !fs.existsSync(sourcePath)) || !fs.existsSync(path.resolve(process.cwd(), path.dirname(dest), source))) { + common.error('Source file does not exist', true); + } fs.symlinkSync(source, dest, os.platform() === "win32" ? "junction" : null); } else { + if (!fs.existsSync(source)) { + common.error('Source file does not exist', true); + } fs.linkSync(source, dest, os.platform() === "win32" ? "junction" : null); } }