diff --git a/lib/local-fs.js b/lib/local-fs.js index a5b71cccd..a19a49a05 100644 --- a/lib/local-fs.js +++ b/lib/local-fs.js @@ -208,39 +208,43 @@ Storage.prototype.path_to = function(file) { } Storage.prototype.create = function(name, value, cb) { - create(this.path + '/' + name, value, cb); + create(this.path + '/' + name, value, cb) } Storage.prototype.create_json = function(name, value, cb) { - create(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb); + create(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb) } Storage.prototype.update = function(name, value, cb) { - update(this.path + '/' + name, value, cb); + update(this.path + '/' + name, value, cb) } Storage.prototype.update_json = function(name, value, cb) { - update(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb); + update(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb) } Storage.prototype.write = function(name, value, cb) { - write(this.path + '/' + name, value, cb); + write(this.path + '/' + name, value, cb) } Storage.prototype.write_json = function(name, value, cb) { - write(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb); + write(this.path + '/' + name, JSON.stringify(value, null, '\t'), cb) } Storage.prototype.write_stream = function(name, value, cb) { - return write_stream(this.path + '/' + name, value, cb); + return write_stream(this.path + '/' + name, value, cb) } Storage.prototype.read_stream = function(name, cb) { - return read_stream(this.path + '/' + name, cb); + return read_stream(this.path + '/' + name, cb) } Storage.prototype.unlink = function(name, cb) { - fs.unlink(this.path + '/' + name, cb); + fs.unlink(this.path + '/' + name, cb) +} + +Storage.prototype.rmdir = function(name, cb) { + fs.rmdir(this.path + '/' + name, cb) } module.exports = Storage; diff --git a/lib/local-storage.js b/lib/local-storage.js index 9ccacfa4d..874ec35b1 100644 --- a/lib/local-storage.js +++ b/lib/local-storage.js @@ -59,15 +59,20 @@ Storage.prototype.add_package = function(name, metadata, callback) { } Storage.prototype.remove_package = function(name, callback) { - this.storage.unlink(name + '/' + info_file, function(err) { + var self = this + self.storage.unlink(name + '/' + info_file, function(err) { if (err && err.code === 'ENOENT') { return callback(new UError({ status: 404, msg: 'no such package available', - })); + })) } - callback(); - }); + + // try to unlink the directory, but ignore errors because it can fail + self.storage.rmdir(name, function(err) { + callback() + }) + }) } Storage.prototype._read_create_package = function(name, callback) {