Rannig from other paths. Property files to array.

This commit is contained in:
Diego A. Zapata Häntsch 2019-07-11 11:20:14 -03:00 committed by Diego Zapata
parent 5608021675
commit 9205c9f079
2 changed files with 26 additions and 0 deletions
lib/providers/filesystem
test

View File

@ -32,6 +32,12 @@ module.exports.createClient = function(options) {
function FileSystemProvider(options) { function FileSystemProvider(options) {
options = options || {}; options = options || {};
if (!path.isAbsolute(options.root)) {
var basePath = path.dirname(path.dirname(require.main.filename));
options.root = path.join(basePath, options.root);
}
this.root = options.root; this.root = options.root;
var exists = fs.existsSync(this.root); var exists = fs.existsSync(this.root);
if (!exists) { if (!exists) {
@ -104,6 +110,11 @@ FileSystemProvider.prototype.getContainers = function(cb) {
fs.readdir(self.root, function(err, files) { fs.readdir(self.root, function(err, files) {
var containers = []; var containers = [];
var tasks = []; var tasks = [];
if (!files) {
files = [];
}
files.forEach(function(f) { files.forEach(function(f) {
tasks.push(fs.stat.bind(fs, path.join(self.root, f))); tasks.push(fs.stat.bind(fs, path.join(self.root, f)));
}); });

View File

@ -31,6 +31,21 @@ describe('FileSystem based storage provider', function() {
process.nextTick(done); process.nextTick(done);
}); });
it('should work even it is ran from other path', function(done) {
process.chdir('../../../');
try {
console.log(`running from ${process.cwd()}`);
client = new FileSystemProvider({
root: path.join(__dirname, 'storage'),
});
process.nextTick(done);
} catch (error) {
process.nextTick(done(error));
}
});
it('should complain if the root directory doesn\'t exist', function(done) { it('should complain if the root directory doesn\'t exist', function(done) {
try { try {
client = new FileSystemProvider({ client = new FileSystemProvider({