This repository was archived by the owner on Jul 3, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,13 @@ const rimraf = BB.promisify(require('rimraf'))
9
9
module . exports = rm
10
10
function rm ( cache , integrity ) {
11
11
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
15
19
}
16
20
} )
17
21
}
Original file line number Diff line number Diff line change @@ -215,7 +215,9 @@ function formatEntry (cache, entry) {
215
215
}
216
216
217
217
function readdirOrEmpty ( dir ) {
218
- return readdirAsync ( dir ) . catch ( { code : 'ENOENT' } , ( ) => [ ] )
218
+ return readdirAsync ( dir )
219
+ . catch ( { code : 'ENOENT' } , ( ) => [ ] )
220
+ . catch ( { code : 'ENOTDIR' } , ( ) => [ ] )
219
221
}
220
222
221
223
function nop ( ) {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const testDir = require('./util/test-dir')(__filename)
11
11
12
12
const CACHE = path . join ( testDir , 'cache' )
13
13
const contentPath = require ( '../lib/content/path' )
14
+ const File = Tacks . File
14
15
15
16
const ls = require ( '..' ) . ls
16
17
@@ -88,6 +89,25 @@ test('separate keys in conflicting buckets', function (t) {
88
89
89
90
test ( 'works fine on an empty/missing cache' , function ( t ) {
90
91
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' )
92
112
} )
93
113
} )
You can’t perform that action at this time.
0 commit comments