diff --git a/lib/factory.js b/lib/factory.js index 7d81058..f59de4f 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -6,15 +6,17 @@ function createClient(options) { options = options || {}; var provider = options.provider || 'filesystem'; + var handler; try { // Try to load the provider from providers folder - provider = require('./providers/' + provider); - return provider.createClient(options); + handler = require('./providers/' + provider); } catch (err) { // Fall back to pkgcloud - return require('pkgcloud').storage.createClient(options); + handler = require('pkgcloud').storage; } + + return handler.createClient(options); } /** @@ -33,4 +35,4 @@ function getProvider(provider) { } module.exports.createClient = createClient; -module.exports.getProvider = getProvider; \ No newline at end of file +module.exports.getProvider = getProvider; diff --git a/lib/providers/filesystem/index.js b/lib/providers/filesystem/index.js index e2b4a23..e56106c 100644 --- a/lib/providers/filesystem/index.js +++ b/lib/providers/filesystem/index.js @@ -18,6 +18,10 @@ module.exports.createClient = function (options) { function FileSystemProvider(options) { options = options || {}; this.root = options.root; + var exists = fs.existsSync(this.root); + if (!exists) { + throw new Error('Path does not exist: ' + this.root); + } var stat = fs.statSync(this.root); if (!stat.isDirectory()) { throw new Error('Invalid directory: ' + this.root); @@ -210,4 +214,4 @@ FileSystemProvider.prototype.removeFile = function (container, file, cb) { var filePath = path.join(this.root, container, file); fs.unlink(filePath, cb); -} \ No newline at end of file +}