Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

findit

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

findit - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

test/symlinks.js

106

index.js
var fs = require('fs');
var path = require('path');
var EventEmitter = require('events').EventEmitter;
var Seq = require('seq');
function createInodeChecker() {
var inodes = {};
return function inodeSeen(inode) {
if (inodes[inode]) {
return true;
} else {
inodes[inode] = true;
return false;
}
}
}
exports = module.exports = find;
exports.find = find;
function find (base, cb) {
function find (base, options, cb) {
cb = arguments[arguments.length - 1];
if (typeof(cb) !== 'function') {
cb = undefined;
}
var em = new EventEmitter;
var inodes = {};
var inodeSeen = createInodeChecker();

@@ -17,3 +34,3 @@ function finder (dir, f) {

var p = dir + '/' + file;
fs.stat(p, this.into(p));
fs.lstat(p, this.into(p));
})

@@ -28,3 +45,3 @@ .seq(function () {

if (inodes[stat.ino]) {
if (inodeSeen(stat.ino)) {
// already seen this inode, probably a recursive symlink

@@ -36,3 +53,21 @@ this(null);

if (stat.isDirectory()) {
if (stat.isSymbolicLink()) {
em.emit('link', file, stat);
if (options && options.follow_symlinks) {
path.exists(file, function(exists) {
if (exists) {
fs.readlink(file, function(err, resolvedPath) {
if (err) {
em.emit('error', err);
} else {
finder(path.resolve(path.dir(file), resolvedPath));
}
});
}
});
} else {
this(null);
}
}
else if (stat.isDirectory()) {
em.emit('directory', file, stat);

@@ -45,4 +80,2 @@ finder(file, this);

}
inodes[stat.ino] = true;
}

@@ -55,11 +88,17 @@ })

fs.stat(base, function (err, s) {
fs.lstat(base, function (err, s) {
if (err) {
em.emit('error', err);
}
else if (s.isDirectory()) {
if (s.isDirectory()) {
finder(base, em.emit.bind(em, 'end'));
}
else if (s.isSymbolicLink()) {
if (cb) cb(base, s);
em.emit('link', base, s);
em.emit('end');
}
else {
em.emit('file', base);
if (cb) cb(base, s);
em.emit('file', base, s);
em.emit('end');

@@ -72,23 +111,38 @@ }

exports.findSync = function findSync (dir, cb) {
var rootStat = fs.statSync(dir);
if (!rootStat.isDirectory()) {
if (cb) cb(dir, rootStat);
return [dir];
exports.findSync = function findSync(dir, options, callback) {
cb = arguments[arguments.length - 1];
if (typeof(cb) !== 'function') {
cb = undefined;
}
return fs.readdirSync(dir).reduce(function (files, file) {
var p = dir + '/' + file;
var stat = fs.statSync(p);
if (cb) cb(p, stat);
files.push(p);
var inodeSeen = createInodeChecker();
var files = [];
var fileQueue = [];
var processFile = function processFile(file) {
var stat = fs.lstatSync(file);
if (inodeSeen(stat.ino)) {
return;
}
files.push(file);
cb && cb(file, stat)
if (stat.isDirectory()) {
files.push.apply(files, findSync(p, cb));
fs.readdirSync(file).forEach(function(f) { fileQueue.push(path.join(file, f)); });
} else if (stat.isSymbolicLink()) {
if (options && options.follow_symlinks && path.existsSync(file)) {
fileQueue.push(fs.realpathSync(file));
}
}
return files;
}, []);
};
/* we don't include the starting directory unless it is a file */
var stat = fs.lstatSync(dir);
if (stat.isDirectory()) {
fs.readdirSync(dir).forEach(function(f) { fileQueue.push(path.join(dir, f)); });
} else {
fileQueue.push(dir);
}
while (fileQueue.length > 0) {
processFile(fileQueue.shift());
}
return files;
};
exports.find.sync = exports.findSync;
{
"name" : "findit",
"version" : "0.1.1",
"version" : "0.1.2",
"description" : "Walk a directory tree.",

@@ -13,2 +13,5 @@ "main" : "./index.js",

},
"scripts" : {
"test" : "expresso"
},
"repository" : {

@@ -15,0 +18,0 @@ "type" : "git",

@@ -5,2 +5,9 @@ var assert = require('assert');

path.relative = path.relative || function (base, dir) {
return dir.indexOf(base + '/') === 0
? dir.slice(base.length + 1)
: dir
;
};
exports.cbSync = function () {

@@ -7,0 +14,0 @@ var files = [];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc