Rannig from other paths. Property files to array.
This commit is contained in:
parent
5608021675
commit
9205c9f079
|
@ -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)));
|
||||||
});
|
});
|
||||||
|
|
|
@ -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({
|
||||||
|
|
Loading…
Reference in New Issue