parent
412c1ab5bc
commit
13400e3e58
34
lib/fs.js
34
lib/fs.js
@ -532,25 +532,35 @@ fs.readlinkSync = function(path) {
|
|||||||
return binding.readlink(pathModule._makeLong(path));
|
return binding.readlink(pathModule._makeLong(path));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function preprocessSymlinkDestination(path, type) {
|
||||||
|
if (!isWindows) {
|
||||||
|
// No preprocessing is needed on Unix.
|
||||||
|
return path;
|
||||||
|
} else if (type === 'junction') {
|
||||||
|
// Junctions paths need to be absolute and \\?\-prefixed.
|
||||||
|
return pathModule._makeLong(path);
|
||||||
|
} else {
|
||||||
|
// Windows symlinks don't tolerate forward slashes.
|
||||||
|
return ('' + path).replace(/\//g, '\\');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fs.symlink = function(destination, path, type_, callback) {
|
fs.symlink = function(destination, path, type_, callback) {
|
||||||
var type = (typeof(type_) == 'string' ? type_ : null);
|
var type = (typeof type_ === 'string' ? type_ : null);
|
||||||
var callback = makeCallback(arguments[arguments.length - 1]);
|
var callback = makeCallback(arguments[arguments.length - 1]);
|
||||||
|
|
||||||
if (isWindows && type === 'junction') {
|
binding.symlink(preprocessSymlinkDestination(destination),
|
||||||
destination = pathModule._makeLong(destination);
|
pathModule._makeLong(path),
|
||||||
}
|
type,
|
||||||
|
callback);
|
||||||
binding.symlink(destination,
|
|
||||||
pathModule._makeLong(path), type, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.symlinkSync = function(destination, path, type) {
|
fs.symlinkSync = function(destination, path, type) {
|
||||||
if (isWindows && type === 'junction') {
|
type = (typeof type === 'string' ? type : null);
|
||||||
destination = pathModule._makeLong(destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
return binding.symlink(destination,
|
return binding.symlink(preprocessSymlinkDestination(destination),
|
||||||
pathModule._makeLong(path), type);
|
pathModule._makeLong(path),
|
||||||
|
type);
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.link = function(srcpath, dstpath, callback) {
|
fs.link = function(srcpath, dstpath, callback) {
|
||||||
|
@ -33,14 +33,6 @@ if (isWindows) {
|
|||||||
// something like "C:\\"
|
// something like "C:\\"
|
||||||
root = process.cwd().substr(0, 3);
|
root = process.cwd().substr(0, 3);
|
||||||
|
|
||||||
// Symlinks MUST use \ paths, never / paths.
|
|
||||||
fs._symlinkSync = fs.symlinkSync;
|
|
||||||
fs.symlinkSync = function(a, b, type) {
|
|
||||||
a = a.split('/').join('\\');
|
|
||||||
b = b.split('/').join('\\');
|
|
||||||
return fs._symlinkSync(a, b, type);
|
|
||||||
};
|
|
||||||
|
|
||||||
// On Windows, creating symlinks requires admin privileges.
|
// On Windows, creating symlinks requires admin privileges.
|
||||||
// We'll only try to run symlink test if we have enough privileges.
|
// We'll only try to run symlink test if we have enough privileges.
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user