Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.readlink(src, (err, resolvedSrc) => {
if (err) return cb(err)
if (opts.dereference) {
resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
}
if (!destStat) {
return fs.symlink(resolvedSrc, dest, cb)
} else {
fs.readlink(dest, (err, resolvedDest) => {
if (err) {
// dest exists and is a regular file or directory,
// Windows may throw UNKNOWN error. If dest already exists,
// fs throws error anyway, so no need to guard against it here.
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest, cb)
return cb(err)
}
if (opts.dereference) {
resolvedDest = path.resolve(process.cwd(), resolvedDest)
}
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
}
// do not copy if src is a subdir of dest since unlinking
// dest in this case would result in removing src contents
LinkWriter.prototype._create = function () {
// console.error(" LW _create")
var me = this
, hard = me.type === "Link" || process.platform === "win32"
, link = hard ? "link" : "symlink"
, lp = hard ? path.resolve(me.dirname, me.linkpath) : me.linkpath
// can only change the link path by clobbering
// For hard links, let's just assume that's always the case, since
// there's no good way to read them if we don't already know.
if (hard) return clobber(me, lp, link)
fs.readlink(me._path, function (er, p) {
// only skip creation if it's exactly the same link
if (p && p === lp) return finish(me)
clobber(me, lp, link)
})
}
function checkDest (dest, cb) {
fs.readlink(dest, (err, resolvedPath) => {
if (err) {
if (err.code === 'ENOENT') return cb(null, notExist)
// dest exists and is a regular file or directory, Windows may throw UNKNOWN error.
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return cb(null, existsReg)
return cb(err)
}
return cb(null, resolvedPath) // dest exists and is a symlink
})
}
lstat(path, iferr(cb, function (stat) {
if (stat.isSymbolicLink()) {
readlink(path, cb)
} else {
readCmdShim(path, function (er, source) {
if (!er) return cb(null, source)
// lstat wouldn't return an error on these, so we don't either.
if (er.code === 'ENOTASHIM' || er.code === 'EISDIR') {
return cb(null, null)
} else {
return cb(er)
}
})
}
}))
}
}, function (contents) {
var group = f.group();
links = contents;
if (links && links.length > 0) {
for (var ii = 0, len = links.length; ii < len; ++ii) {
var filePath = path.join(pluginsRoot, links[ii]);
links[ii] = filePath;
fs.readlink(filePath, group.slot());
}
} else {
logger.log("No plugin JS currently installed");
// Stop ff call chain here
f.succeed();
}
}, function (targets) {
var group = f.group();
LinkReader.prototype._stat = function (currentStat) {
var self = this
fs.readlink(self._path, function (er, linkpath) {
if (er) return self.error(er)
self.linkpath = self.props.linkpath = linkpath
self.emit('linkpath', linkpath)
Reader.prototype._stat.call(self, currentStat)
})
}
function onLink (link) {
var target = link.replace(currentPath, targetPath)
fs.readlink(link, function (err, resolvedPath) {
if (err) return onError(err)
checkLink(resolvedPath, target)
})
}
isWritable(target, function (writable) {
if (writable) {
return makeLink(resolvedPath, target)
}
fs.readlink(target, function (err, targetDest) {
if (err) return onError(err)
if (dereference) {
targetDest = path.resolve(basePath, targetDest)
}
if (targetDest === resolvedPath) {
return doneOne()
}
return rmFile(target, function () {
makeLink(resolvedPath, target)
})
})
})
}
function onLink (link) {
var target = link.replace(currentPath, targetPath)
fs.readlink(link, function (err, resolvedPath) {
if (err) return onError(err)
checkLink(resolvedPath, target)
})
}
function onLink (link) {
var target = link.replace(currentPath, targetPath)
fs.readlink(link, function (err, resolvedPath) {
if (err) return onError(err)
checkLink(resolvedPath, target)
})
}