Check that source exists for hard links

This commit is contained in:
Brandon Freitag 2016-01-25 01:48:06 -08:00
parent fd27d85317
commit 39ab73ff61

View File

@ -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);
}
}