Skip to content

Commit

Permalink
Files Provider: Make sure path exists before searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed Jul 2, 2012
1 parent f2da456 commit 8a6d717
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/prey/plugins/providers/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// GPLv3 Licensed
//////////////////////////////////////////

var util = require('util'),
var fs = require('fs'),
util = require('util'),
Getters = require('./../../../getters'),
finder = require('./lib/finder');

Expand Down Expand Up @@ -63,24 +64,29 @@ var Files = function(){

var path = options.path || process.env.HOME;
var matches_criteria = options.criteria;
var files = [];
var matches = [];

finder.eachFileOrDirectory(path, function(err, file, stat) {
fs.exists(path, function(exists){

// if we get a hidden file or error, skip to next
if (err || /\/\./.test(file)) return;
if(!exists) return callback(new Error("Path not found: " + path))

if(!stat.isDirectory() && matches_criteria && matches_criteria(file, stat)) {
// console.log("File matches criteria: " + file)
files.push(file);
}
finder.eachFileOrDirectory(path, function(err, file, stat) {

}, function(err, files, stats){
// if we get a hidden file or error, skip to next
if (err || /\/\./.test(file)) return;

callback(err, files);
if(!stat.isDirectory() && matches_criteria && matches_criteria(file, stat)) {
// console.log("File matches criteria: " + file)
matches.push(file);
}

});
}, function(){

callback(matches);

});

});

};

Expand Down

0 comments on commit 8a6d717

Please sign in to comment.