Merge pull request #279 from diegoazh/master

Fixes in PRs 252 and 242
This commit is contained in:
Diana Lau 2019-07-20 17:32:08 -04:00 committed by GitHub
commit 963f334ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -32,6 +32,12 @@ module.exports.createClient = function(options) {
function FileSystemProvider(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;
var exists = fs.existsSync(this.root);
if (!exists) {
@ -104,6 +110,11 @@ FileSystemProvider.prototype.getContainers = function(cb) {
fs.readdir(self.root, function(err, files) {
var containers = [];
var tasks = [];
if (!files) {
files = [];
}
files.forEach(function(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);
});
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) {
try {
client = new FileSystemProvider({