Skip to content
This repository was archived by the owner on Jul 3, 2019. It is now read-only.

Commit ac90bc0

Browse files
committed
fix(rm): stop crashing if content is missing on rm
1 parent 950b19a commit ac90bc0

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

lib/content/rm.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ const rimraf = BB.promisify(require('rimraf'))
99
module.exports = rm
1010
function rm (cache, integrity) {
1111
return hasContent(cache, integrity).then(content => {
12-
const sri = content.sri
13-
if (sri) {
14-
return rimraf(contentPath(cache, sri))
12+
if (content) {
13+
const sri = content.sri
14+
if (sri) {
15+
return rimraf(contentPath(cache, sri)).then(() => true)
16+
}
17+
} else {
18+
return false
1519
}
1620
})
1721
}

lib/entry-index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ function formatEntry (cache, entry) {
215215
}
216216

217217
function readdirOrEmpty (dir) {
218-
return readdirAsync(dir).catch({code: 'ENOENT'}, () => [])
218+
return readdirAsync(dir)
219+
.catch({code: 'ENOENT'}, () => [])
220+
.catch({code: 'ENOTDIR'}, () => [])
219221
}
220222

221223
function nop () {

test/ls.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const testDir = require('./util/test-dir')(__filename)
1111

1212
const CACHE = path.join(testDir, 'cache')
1313
const contentPath = require('../lib/content/path')
14+
const File = Tacks.File
1415

1516
const ls = require('..').ls
1617

@@ -88,6 +89,25 @@ test('separate keys in conflicting buckets', function (t) {
8889

8990
test('works fine on an empty/missing cache', function (t) {
9091
return ls(CACHE).then(listing => {
91-
t.deepEqual(listing, {})
92+
t.deepEqual(listing, {}, 'returned an empty listing')
93+
})
94+
})
95+
96+
test('ignores non-dir files', function (t) {
97+
const index = CacheIndex({
98+
'whatever': {
99+
key: 'whatever',
100+
integrity: 'sha512-deadbeef',
101+
time: 12345,
102+
metadata: 'omgsometa',
103+
size: 234234
104+
}
105+
})
106+
index.contents['garbage'] = File('hello world')
107+
const fixture = new Tacks(index)
108+
fixture.create(CACHE)
109+
return ls(CACHE).then(listing => {
110+
t.equal(Object.keys(listing).length, 1, 'only 1 item in listing')
111+
t.equal(listing.whatever.key, 'whatever', 'only the correct entry listed')
92112
})
93113
})

0 commit comments

Comments
 (0)