commit
963f334ee7
|
@ -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)));
|
||||
});
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue