@@ -13,7 +13,10 @@ const path = require('path')
13
13
const rimraf = BB . promisify ( require ( 'rimraf' ) )
14
14
const ssri = require ( 'ssri' )
15
15
16
- BB . promisifyAll ( fs )
16
+ const stat = BB . promisify ( fs . stat )
17
+ const truncate = BB . promisify ( fs . truncate )
18
+ const writeFile = BB . promisify ( fs . writeFile )
19
+ const readFile = BB . promisify ( fs . readFile )
17
20
18
21
const VerifyOpts = figgyPudding ( {
19
22
concurrency : {
@@ -40,7 +43,7 @@ function verify (cache, opts) {
40
43
] , ( stats , step , i ) => {
41
44
const label = step . name || `step #${ i } `
42
45
const start = new Date ( )
43
- return BB . resolve ( step ( cache , opts ) ) . then ( s => {
46
+ return BB . resolve ( step ( cache , opts ) ) . then ( ( s ) => {
44
47
s && Object . keys ( s ) . forEach ( k => {
45
48
stats [ k ] = s [ k ]
46
49
} )
@@ -96,7 +99,7 @@ function garbageCollect (cache, opts) {
96
99
follow : false ,
97
100
nodir : true ,
98
101
nosort : true
99
- } ) . then ( files => {
102
+ } ) . then ( ( files ) => {
100
103
return BB . resolve ( {
101
104
verifiedContent : 0 ,
102
105
reclaimedCount : 0 ,
@@ -109,7 +112,7 @@ function garbageCollect (cache, opts) {
109
112
const algo = split [ split . length - 4 ]
110
113
const integrity = ssri . fromHex ( digest , algo )
111
114
if ( liveContent . has ( integrity . toString ( ) ) ) {
112
- return verifyContent ( f , integrity ) . then ( info => {
115
+ return verifyContent ( f , integrity ) . then ( ( info ) => {
113
116
if ( ! info . valid ) {
114
117
stats . reclaimedCount ++
115
118
stats . badContentCount ++
@@ -123,7 +126,7 @@ function garbageCollect (cache, opts) {
123
126
} else {
124
127
// No entries refer to this content. We can delete.
125
128
stats . reclaimedCount ++
126
- return fs . statAsync ( f ) . then ( s => {
129
+ return stat ( f ) . then ( ( s ) => {
127
130
return rimraf ( f ) . then ( ( ) => {
128
131
stats . reclaimedSize += s . size
129
132
return stats
@@ -137,9 +140,9 @@ function garbageCollect (cache, opts) {
137
140
}
138
141
139
142
function verifyContent ( filepath , sri ) {
140
- return fs . statAsync ( filepath ) . then ( stat => {
143
+ return stat ( filepath ) . then ( ( s ) => {
141
144
const contentInfo = {
142
- size : stat . size ,
145
+ size : s . size ,
143
146
valid : true
144
147
}
145
148
return ssri . checkStream (
@@ -161,7 +164,7 @@ function verifyContent (filepath, sri) {
161
164
162
165
function rebuildIndex ( cache , opts ) {
163
166
opts . log . silly ( 'verify' , 'rebuilding index' )
164
- return index . ls ( cache ) . then ( entries => {
167
+ return index . ls ( cache ) . then ( ( entries ) => {
165
168
const stats = {
166
169
missingContent : 0 ,
167
170
rejectedEntries : 0 ,
@@ -194,12 +197,12 @@ function rebuildIndex (cache, opts) {
194
197
}
195
198
196
199
function rebuildBucket ( cache , bucket , stats , opts ) {
197
- return fs . truncateAsync ( bucket . _path ) . then ( ( ) => {
200
+ return truncate ( bucket . _path ) . then ( ( ) => {
198
201
// This needs to be serialized because cacache explicitly
199
202
// lets very racy bucket conflicts clobber each other.
200
203
return BB . mapSeries ( bucket , entry => {
201
204
const content = contentPath ( cache , entry . integrity )
202
- return fs . statAsync ( content ) . then ( ( ) => {
205
+ return stat ( content ) . then ( ( ) => {
203
206
return index . insert ( cache , entry . key , entry . integrity , {
204
207
metadata : entry . metadata ,
205
208
size : entry . size
@@ -225,15 +228,16 @@ function writeVerifile (cache, opts) {
225
228
const verifile = path . join ( cache , '_lastverified' )
226
229
opts . log . silly ( 'verify' , 'writing verifile to ' + verifile )
227
230
try {
228
- return fs . writeFileAsync ( verifile , '' + ( + ( new Date ( ) ) ) )
231
+ return writeFile ( verifile , '' + ( + ( new Date ( ) ) ) )
229
232
} finally {
230
233
fixOwner . chownr . sync ( cache , verifile )
231
234
}
232
235
}
233
236
234
237
module . exports . lastRun = lastRun
238
+
235
239
function lastRun ( cache ) {
236
- return fs . readFileAsync (
240
+ return readFile (
237
241
path . join ( cache , '_lastverified' ) , 'utf8'
238
- ) . then ( data => new Date ( + data ) )
242
+ ) . then ( ( data ) => new Date ( + data ) )
239
243
}
0 commit comments