Skip to content

Commit

Permalink
Align .symlink with .dest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Oct 23, 2017
1 parent c3fee96 commit 758df57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
44 changes: 26 additions & 18 deletions lib/symlink/link-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,16 @@ var isWindows = (os.platform() === 'win32');
function linkStream(optResolver) {

function linkFile(file, enc, callback) {
// This option provides a way to create a Junction instead of a
// Directory symlink on Windows. This comes with the following caveats:
// * NTFS Junctions cannot be relative.
// * NTFS Junctions MUST be directories.
// * NTFS Junctions must be on the same file system.
// * Most products CANNOT detect a directory is a Junction:
// This has the side effect of possibly having a whole directory
// deleted when a product is deleting the Junction directory.
// For example, JetBrains product lines will delete the entire
// contents of the TARGET directory because the product does not
// realize it's a symlink as the JVM and Node return false for isSymlink.
var useJunctions = isWindows && optResolver.resolve('useJunctions', file);

var isRelative = optResolver.resolve('relativeSymlinks', file);
var flag = optResolver.resolve('flag', file);

if (isWindows) {
fs.stat(file.symlink, onStat);
} else {
onStat(null, file.stat);
if (!isWindows) {
// On non-Windows, just use 'file'
return createLinkWithType('file');
}

fs.stat(file.symlink, onStat);

function onStat(statErr, stat) {
if (statErr && statErr.code !== 'ENOENT') {
return onWritten(statErr);
Expand All @@ -45,9 +33,29 @@ function linkStream(optResolver) {
stat = file.stat;
}

// This option provides a way to create a Junction instead of a
// Directory symlink on Windows. This comes with the following caveats:
// * NTFS Junctions cannot be relative.
// * NTFS Junctions MUST be directories.
// * NTFS Junctions must be on the same file system.
// * Most products CANNOT detect a directory is a Junction:
// This has the side effect of possibly having a whole directory
// deleted when a product is deleting the Junction directory.
// For example, JetBrains product lines will delete the entire
// contents of the TARGET directory because the product does not
// realize it's a symlink as the JVM and Node return false for isSymlink.

// This function is Windows only, so we don't need to check again
var useJunctions = optResolver.resolve('useJunctions', file);

var symDirType = useJunctions ? 'junction' : 'dir';
var symType = stat && stat.isDirectory() ? symDirType : 'file';
// Must check if isDirectory is defined
var symType = stat && stat.isDirectory && stat.isDirectory() ? symDirType : 'file';

createLinkWithType(symType);
}

function createLinkWithType(symType) {
// This is done after prepare() to use the adjusted file.base property
if (isRelative && symType !== 'junction') {
file.symlink = path.relative(file.base, file.symlink);
Expand Down
1 change: 1 addition & 0 deletions lib/symlink/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function prepareSymlink(folderResolver, optResolver) {
file.stat.mode = LINK_MODE;
file.cwd = cwd;
file.base = basePath;
// This is the path we are linking *TO*
file.symlink = file.path;
file.path = writePath;
// We have to set contents to null for a link
Expand Down

0 comments on commit 758df57

Please sign in to comment.