Return empty hash from list if directory doesn't exist.

Conflicts:

	test/list.test.js
This commit is contained in:
Will White
2012-03-28 20:27:31 -04:00
committed by Young Hahn
parent 889735db2b
commit 25c2a99d72
2 changed files with 4 additions and 8 deletions

View File

@@ -76,6 +76,7 @@ MBTiles.registerProtocols = function(tilelive) {
MBTiles.list = function(filepath, callback) {
filepath = path.resolve(filepath);
fs.readdir(filepath, function(err, files) {
if (err && err.code === 'ENOENT') return callback(null, {});
if (err) return callback(err);
for (var result = {}, i = 0; i < files.length; i++) {
var name = files[i].match(/^([\w-]+)\.mbtiles$/);

View File

@@ -15,14 +15,9 @@ exports['list'] = function(beforeExit, assert) {
var completed = false; beforeExit(function() { assert.ok(completed); });
MBTiles.list(fixtures.doesnotexist, function(err, list) {
assert.ok(err);
assert.ok(err.code.match(/^ENOENT/));
MBTiles.list(fixtures.doesnotexist, function(err, list) {
completed = true;
assert.ok(err);
assert.ok(err.code.match(/^ENOENT/));
});
completed = true;
assert.equal(err, null);
assert.deepEqual(list, {});
});
};