Fix bug making provider fallthrough to pkgcloud when a directory doesn't exist, making a very unintuitive error.

This commit is contained in:
Stephen Belanger 2013-10-29 17:54:32 -07:00
parent 6cbf564132
commit 50ce215142
2 changed files with 11 additions and 5 deletions

View File

@ -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);
}
/**

View File

@ -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);