@@ -23,6 +23,12 @@ module.exports = function pin (self) {
23
23
const repo = self . _repo
24
24
const dag = self . dag
25
25
const pinset = createPinSet ( dag )
26
+ const types = {
27
+ direct : 'direct' ,
28
+ recursive : 'recursive' ,
29
+ indirect : 'indirect' ,
30
+ all : 'all'
31
+ }
26
32
27
33
let directPins = new Set ( )
28
34
let recursivePins = new Set ( )
@@ -61,14 +67,14 @@ module.exports = function pin (self) {
61
67
// create a DAGLink to the node with direct pins
62
68
cb => async . waterfall ( [
63
69
cb => pinset . storeSet ( directKeys ( ) , cb ) ,
64
- ( node , cb ) => DAGLink . create ( pin . types . direct , node . size , node . multihash , cb ) ,
70
+ ( node , cb ) => DAGLink . create ( types . direct , node . size , node . multihash , cb ) ,
65
71
( link , cb ) => { dLink = link ; cb ( null ) }
66
72
] , cb ) ,
67
73
68
74
// create a DAGLink to the node with recursive pins
69
75
cb => async . waterfall ( [
70
76
cb => pinset . storeSet ( recursiveKeys ( ) , cb ) ,
71
- ( node , cb ) => DAGLink . create ( pin . types . recursive , node . size , node . multihash , cb ) ,
77
+ ( node , cb ) => DAGLink . create ( types . recursive , node . size , node . multihash , cb ) ,
72
78
( link , cb ) => { rLink = link ; cb ( null ) }
73
79
] , cb ) ,
74
80
@@ -98,13 +104,6 @@ module.exports = function pin (self) {
98
104
}
99
105
100
106
const pin = {
101
- types : {
102
- direct : 'direct' ,
103
- recursive : 'recursive' ,
104
- indirect : 'indirect' ,
105
- all : 'all'
106
- } ,
107
-
108
107
add : promisify ( ( paths , options , callback ) => {
109
108
if ( typeof options === 'function' ) {
110
109
callback = options
@@ -177,7 +176,7 @@ module.exports = function pin (self) {
177
176
178
177
// verify that each hash can be unpinned
179
178
async . map ( mhs , ( multihash , cb ) => {
180
- pin . _isPinnedWithType ( multihash , pin . types . all , ( err , res ) => {
179
+ pin . _isPinnedWithType ( multihash , types . all , ( err , res ) => {
181
180
if ( err ) { return cb ( err ) }
182
181
const { pinned, reason } = res
183
182
const key = toB58String ( multihash )
@@ -186,13 +185,13 @@ module.exports = function pin (self) {
186
185
}
187
186
188
187
switch ( reason ) {
189
- case ( pin . types . recursive ) :
188
+ case ( types . recursive ) :
190
189
if ( recursive ) {
191
190
return cb ( null , key )
192
191
} else {
193
192
return cb ( new Error ( `${ key } is pinned recursively` ) )
194
193
}
195
- case ( pin . types . direct ) :
194
+ case ( types . direct ) :
196
195
return cb ( null , key )
197
196
default :
198
197
return cb ( new Error (
@@ -223,7 +222,7 @@ module.exports = function pin (self) {
223
222
} ) ,
224
223
225
224
ls : promisify ( ( paths , options , callback ) => {
226
- let type = pin . types . all
225
+ let type = types . all
227
226
if ( typeof paths === 'function' ) {
228
227
callback = paths
229
228
options = null
@@ -239,7 +238,7 @@ module.exports = function pin (self) {
239
238
if ( options && options . type ) {
240
239
type = options . type . toLowerCase ( )
241
240
}
242
- if ( ! pin . types [ type ] ) {
241
+ if ( ! types [ type ] ) {
243
242
return callback ( new Error (
244
243
`Invalid type '${ type } ', must be one of {direct, indirect, recursive, all}`
245
244
) )
@@ -251,7 +250,7 @@ module.exports = function pin (self) {
251
250
if ( err ) { return callback ( err ) }
252
251
253
252
async . mapSeries ( mhs , ( multihash , cb ) => {
254
- pin . _isPinnedWithType ( multihash , pin . types . all , ( err , res ) => {
253
+ pin . _isPinnedWithType ( multihash , types . all , ( err , res ) => {
255
254
if ( err ) { return cb ( err ) }
256
255
const { pinned, reason } = res
257
256
const key = toB58String ( multihash )
@@ -260,16 +259,16 @@ module.exports = function pin (self) {
260
259
}
261
260
262
261
switch ( reason ) {
263
- case pin . types . direct :
264
- case pin . types . recursive :
262
+ case types . direct :
263
+ case types . recursive :
265
264
return cb ( null , {
266
265
hash : key ,
267
266
type : reason
268
267
} )
269
268
default :
270
269
return cb ( null , {
271
270
hash : key ,
272
- type : `${ pin . types . indirect } through ${ reason } `
271
+ type : `${ types . indirect } through ${ reason } `
273
272
} )
274
273
}
275
274
} )
@@ -278,23 +277,23 @@ module.exports = function pin (self) {
278
277
} else {
279
278
// show all pinned items of type
280
279
let pins = [ ]
281
- if ( type === pin . types . direct || type === pin . types . all ) {
280
+ if ( type === types . direct || type === types . all ) {
282
281
pins = pins . concat (
283
282
Array . from ( directPins ) . map ( hash => ( {
284
- type : pin . types . direct ,
283
+ type : types . direct ,
285
284
hash
286
285
} ) )
287
286
)
288
287
}
289
- if ( type === pin . types . recursive || type === pin . types . all ) {
288
+ if ( type === types . recursive || type === types . all ) {
290
289
pins = pins . concat (
291
290
Array . from ( recursivePins ) . map ( hash => ( {
292
- type : pin . types . recursive ,
291
+ type : types . recursive ,
293
292
hash
294
293
} ) )
295
294
)
296
295
}
297
- if ( type === pin . types . indirect || type === pin . types . all ) {
296
+ if ( type === types . indirect || type === types . all ) {
298
297
getIndirectKeys ( ( err , indirects ) => {
299
298
if ( err ) { return callback ( err ) }
300
299
pins = pins
@@ -305,7 +304,7 @@ module.exports = function pin (self) {
305
304
( indirects . includes ( hash ) && ! directPins . has ( hash ) )
306
305
)
307
306
. concat ( indirects . map ( hash => ( {
308
- type : pin . types . indirect ,
307
+ type : types . indirect ,
309
308
hash
310
309
} ) ) )
311
310
return callback ( null , pins )
@@ -318,7 +317,7 @@ module.exports = function pin (self) {
318
317
319
318
_isPinnedWithType : promisify ( ( multihash , type , callback ) => {
320
319
const key = toB58String ( multihash )
321
- const { recursive, direct, all } = pin . types
320
+ const { recursive, direct, all } = types
322
321
// recursive
323
322
if ( ( type === recursive || type === all ) && recursivePins . has ( key ) ) {
324
323
return callback ( null , { pinned : true , reason : recursive } )
@@ -374,8 +373,8 @@ module.exports = function pin (self) {
374
373
}
375
374
376
375
async . parallel ( [
377
- cb => pinset . loadSet ( pinRoot . value , pin . types . recursive , cb ) ,
378
- cb => pinset . loadSet ( pinRoot . value , pin . types . direct , cb )
376
+ cb => pinset . loadSet ( pinRoot . value , types . recursive , cb ) ,
377
+ cb => pinset . loadSet ( pinRoot . value , types . direct , cb )
379
378
] , ( err , [ rKeys , dKeys ] ) => {
380
379
if ( err ) { return callback ( err ) }
381
380
0 commit comments