Skip to content

Commit 963f334

Browse files
authored
Merge pull request #279 from diegoazh/master
Fixes in PRs 252 and 242
2 parents 5608021 + 9205c9f commit 963f334

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/providers/filesystem/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports.createClient = function(options) {
3232

3333
function FileSystemProvider(options) {
3434
options = options || {};
35+
36+
if (!path.isAbsolute(options.root)) {
37+
var basePath = path.dirname(path.dirname(require.main.filename));
38+
options.root = path.join(basePath, options.root);
39+
}
40+
3541
this.root = options.root;
3642
var exists = fs.existsSync(this.root);
3743
if (!exists) {
@@ -104,6 +110,11 @@ FileSystemProvider.prototype.getContainers = function(cb) {
104110
fs.readdir(self.root, function(err, files) {
105111
var containers = [];
106112
var tasks = [];
113+
114+
if (!files) {
115+
files = [];
116+
}
117+
107118
files.forEach(function(f) {
108119
tasks.push(fs.stat.bind(fs, path.join(self.root, f)));
109120
});

test/fs.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ describe('FileSystem based storage provider', function() {
3131
process.nextTick(done);
3232
});
3333

34+
it('should work even it is ran from other path', function(done) {
35+
process.chdir('../../../');
36+
37+
try {
38+
console.log(`running from ${process.cwd()}`);
39+
client = new FileSystemProvider({
40+
root: path.join(__dirname, 'storage'),
41+
});
42+
43+
process.nextTick(done);
44+
} catch (error) {
45+
process.nextTick(done(error));
46+
}
47+
});
48+
3449
it('should complain if the root directory doesn\'t exist', function(done) {
3550
try {
3651
client = new FileSystemProvider({

0 commit comments

Comments
 (0)