From 50ce2151421e7770f08603921811f04e495a8e7d Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Tue, 29 Oct 2013 17:54:32 -0700 Subject: [PATCH] Fix bug making provider fallthrough to pkgcloud when a directory doesn't exist, making a very unintuitive error. --- lib/factory.js | 10 ++++++---- lib/providers/filesystem/index.js | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) 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 +}