From 25c2a99d7216060dc7d2965eec07e0aef03e98e7 Mon Sep 17 00:00:00 2001 From: Will White Date: Wed, 28 Mar 2012 20:27:31 -0400 Subject: [PATCH] Return empty hash from list if directory doesn't exist. Conflicts: test/list.test.js --- lib/mbtiles.js | 1 + test/list.test.js | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/mbtiles.js b/lib/mbtiles.js index bd494ff..d70a700 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -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$/); diff --git a/test/list.test.js b/test/list.test.js index 3a3523f..845f142 100644 --- a/test/list.test.js +++ b/test/list.test.js @@ -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, {}); }); };