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) { function createClient(options) {
options = options || {}; options = options || {};
var provider = options.provider || 'filesystem'; var provider = options.provider || 'filesystem';
var handler;
try { try {
// Try to load the provider from providers folder // Try to load the provider from providers folder
provider = require('./providers/' + provider); handler = require('./providers/' + provider);
return provider.createClient(options);
} catch (err) { } catch (err) {
// Fall back to pkgcloud // 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.createClient = createClient;
module.exports.getProvider = getProvider; module.exports.getProvider = getProvider;

View File

@ -18,6 +18,10 @@ module.exports.createClient = function (options) {
function FileSystemProvider(options) { function FileSystemProvider(options) {
options = options || {}; options = options || {};
this.root = options.root; 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); var stat = fs.statSync(this.root);
if (!stat.isDirectory()) { if (!stat.isDirectory()) {
throw new Error('Invalid directory: ' + this.root); 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); var filePath = path.join(this.root, container, file);
fs.unlink(filePath, cb); fs.unlink(filePath, cb);
} }