@@ -32,27 +32,32 @@ module.exports = verify
32
32
function verify ( cache , opts ) {
33
33
opts = VerifyOpts ( opts )
34
34
opts . log . silly ( 'verify' , 'verifying cache at' , cache )
35
- return BB . reduce ( [
35
+
36
+ const steps = [
36
37
markStartTime ,
37
38
fixPerms ,
38
39
garbageCollect ,
39
40
rebuildIndex ,
40
41
cleanTmp ,
41
42
writeVerifile ,
42
43
markEndTime
43
- ] , ( stats , step , i ) => {
44
+ ]
45
+
46
+ return steps . reduce ( ( promise , step , i ) => {
44
47
const label = step . name || `step #${ i } `
45
48
const start = new Date ( )
46
- return BB . resolve ( step ( cache , opts ) ) . then ( ( s ) => {
47
- s && Object . keys ( s ) . forEach ( k => {
48
- stats [ k ] = s [ k ]
49
+ return promise . then ( ( stats ) => {
50
+ return step ( cache , opts ) . then ( ( s ) => {
51
+ s && Object . keys ( s ) . forEach ( k => {
52
+ stats [ k ] = s [ k ]
53
+ } )
54
+ const end = new Date ( )
55
+ if ( ! stats . runTime ) { stats . runTime = { } }
56
+ stats . runTime [ label ] = end - start
57
+ return BB . resolve ( stats )
49
58
} )
50
- const end = new Date ( )
51
- if ( ! stats . runTime ) { stats . runTime = { } }
52
- stats . runTime [ label ] = end - start
53
- return stats
54
59
} )
55
- } , { } )
60
+ } , BB . resolve ( { } ) )
56
61
. then ( ( stats ) => {
57
62
stats . runTime . total = stats . endTime - stats . startTime
58
63
opts . log . silly ( 'verify' , 'verification finished for' , cache , 'in' , `${ stats . runTime . total } ms` )
@@ -61,11 +66,11 @@ function verify (cache, opts) {
61
66
}
62
67
63
68
function markStartTime ( cache , opts ) {
64
- return { startTime : new Date ( ) }
69
+ return BB . resolve ( { startTime : new Date ( ) } )
65
70
}
66
71
67
72
function markEndTime ( cache , opts ) {
68
- return { endTime : new Date ( ) }
73
+ return BB . resolve ( { endTime : new Date ( ) } )
69
74
}
70
75
71
76
function fixPerms ( cache , opts ) {
@@ -200,22 +205,24 @@ function rebuildBucket (cache, bucket, stats, opts) {
200
205
return truncate ( bucket . _path ) . then ( ( ) => {
201
206
// This needs to be serialized because cacache explicitly
202
207
// lets very racy bucket conflicts clobber each other.
203
- return BB . mapSeries ( bucket , entry => {
204
- const content = contentPath ( cache , entry . integrity )
205
- return stat ( content ) . then ( ( ) => {
206
- return index . insert ( cache , entry . key , entry . integrity , {
207
- metadata : entry . metadata ,
208
- size : entry . size
209
- } ) . then ( ( ) => { stats . totalEntries ++ } )
210
- } ) . catch ( ( err ) => {
211
- if ( err . code === 'ENOENT' ) {
212
- stats . rejectedEntries ++
213
- stats . missingContent ++
214
- return
215
- }
216
- throw err
208
+ return bucket . reduce ( ( promise , entry ) => {
209
+ return promise . then ( ( ) => {
210
+ const content = contentPath ( cache , entry . integrity )
211
+ return stat ( content ) . then ( ( ) => {
212
+ return index . insert ( cache , entry . key , entry . integrity , {
213
+ metadata : entry . metadata ,
214
+ size : entry . size
215
+ } ) . then ( ( ) => { stats . totalEntries ++ } )
216
+ } ) . catch ( ( err ) => {
217
+ if ( err . code === 'ENOENT' ) {
218
+ stats . rejectedEntries ++
219
+ stats . missingContent ++
220
+ return
221
+ }
222
+ throw err
223
+ } )
217
224
} )
218
- } )
225
+ } , BB . resolve ( ) )
219
226
} )
220
227
}
221
228
0 commit comments