Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reflectLinkStat(path, file, callback) {
// Set file.stat to the reflect current state on disk
fs.lstat(path, onLstat);
function onLstat(lstatErr, stat) {
if (lstatErr) {
return callback(lstatErr);
}
file.stat = stat;
callback();
}
}
function copyFile(source, dest, overwrite, callback) {
// Allow callback as third arg.
if (typeof overwrite === 'function') {
callback = overwrite;
overwrite = null;
}
fs.lstat(source, function (err, sourceStats) {
if (err) {
return callback(err);
}
if (!sourceStats.isFile()) {
return callback(new Error("Source is not a file: " + source));
}
fs.lstat(dest, function (err, destStats) {
var rs;
if (err && err.code !== 'ENOENT') {
return callback(err);
}
if (destStats) {
function readLinkOrShim (path, cb) {
validate('SF', arguments)
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 checkGit (folder, cb) {
// if it's a git repo then don't touch it!
fs.lstat(folder, function (er, s) {
if (er || !s.isDirectory()) return cb()
else checkGit_(folder, cb)
})
}
fs.lstat(source, function (err, sourceStats) {
if (err) {
return callback(err);
}
if (!sourceStats.isFile()) {
return callback(new Error("Source is not a file: " + source));
}
fs.lstat(dest, function (err, destStats) {
var rs;
if (err && err.code !== 'ENOENT') {
return callback(err);
}
if (destStats) {
if (overwrite) {
deletePath(dest); // TODO: make this async
} else {
callback(new Error("Destination already exists: " + dest));
return;
}
}
rs = fs.createReadStream(source);
if (er) i = []
installed = i.filter(function (f) { return f.charAt(0) !== "." })
next()
})
readJson(path.resolve(folder, "package.json"), function (er, data) {
obj = copy(data)
if (!parent) {
obj = obj || true
er = null
}
return next(er)
})
fs.lstat(folder, function (er, st) {
if (er) {
if (!parent) real = true
return next(er)
}
fs.realpath(folder, function (er, rp) {
//console.error("realpath(%j) = %j", folder, rp)
real = rp
if (st.isSymbolicLink()) link = rp
next(er)
})
})
var errState = null
, called = false
function next (er) {
if (errState) return
function vacuum (leaf, options, cb) {
assert(typeof leaf === 'string', 'must pass in path to remove')
assert(typeof cb === 'function', 'must pass in callback')
if (!options) options = {}
assert(typeof options === 'object', 'options must be an object')
var log = options.log ? options.log : function () {}
leaf = leaf && resolve(leaf)
var base = options.base && resolve(options.base)
if (base && !isInside(leaf, base)) {
return cb(new Error(leaf + ' is not a child of ' + base))
}
lstat(leaf, function (error, stat) {
if (error) {
if (error.code === 'ENOENT') return cb(null)
log(error.stack)
return cb(error)
}
if (!(stat && (stat.isDirectory() || stat.isSymbolicLink() || stat.isFile()))) {
log(leaf, 'is not a directory, file, or link')
return cb(new Error(leaf + ' is not a directory, file, or link'))
}
if (options.purge) {
log('purging', leaf)
rimraf(leaf, function (error) {
if (error) return cb(error)
function checkForLink (pkg, cb) {
var f = path.join(npm.dir, pkg.name)
fs.lstat(f, function (er, s) {
cb(null, !(er || !s.isSymbolicLink()))
})
}
function isWritable (path, done) {
fs.lstat(path, function (err) {
if (err) {
if (err.code === 'ENOENT') return done(true)
return done(false)
}
return done(false)
})
}
function checkForLink (pkg, cb) {
var f = path.join(npm.dir, pkg.name)
fs.lstat(f, function (er, s) {
cb(null, !(er || !s.isSymbolicLink()))
})
}