@@ -27,107 +27,107 @@ function withTarballStream (spec, opts, streamHandler) {
27
27
opts . resolved &&
28
28
opts . resolved . startsWith ( 'file:' )
29
29
)
30
- ? BB . try ( ( ) => {
30
+ ? BB . try ( ( ) => {
31
31
// NOTE - this is a special shortcut! Packages installed as files do not
32
32
// have a `resolved` field -- this specific case only occurs when you have,
33
33
// say, a git dependency or a registry dependency that you've packaged into
34
34
// a local file, and put that file: spec in the `resolved` field.
35
- opts . log . silly ( 'pacote' , `trying ${ spec } by local file: ${ opts . resolved } ` )
36
- const file = path . resolve ( opts . where || '.' , opts . resolved . substr ( 5 ) )
37
- return statAsync ( file )
38
- . then ( ( ) => {
39
- const verifier = ssri . integrityStream ( { integrity : opts . integrity } )
40
- const stream = fs . createReadStream ( file )
41
- . on ( 'error' , err => verifier . emit ( 'error' , err ) )
42
- . pipe ( verifier )
43
- return streamHandler ( stream )
44
- } )
45
- . catch ( err => {
46
- if ( err . code === 'EINTEGRITY' ) {
47
- opts . log . warn ( 'pacote' , `EINTEGRITY while extracting ${ spec } from ${ file } .You will have to recreate the file.` )
48
- opts . log . verbose ( 'pacote' , `EINTEGRITY for ${ spec } : ${ err . message } ` )
49
- }
50
- throw err
35
+ opts . log . silly ( 'pacote' , `trying ${ spec } by local file: ${ opts . resolved } ` )
36
+ const file = path . resolve ( opts . where || '.' , opts . resolved . substr ( 5 ) )
37
+ return statAsync ( file )
38
+ . then ( ( ) => {
39
+ const verifier = ssri . integrityStream ( { integrity : opts . integrity } )
40
+ const stream = fs . createReadStream ( file )
41
+ . on ( 'error' , err => verifier . emit ( 'error' , err ) )
42
+ . pipe ( verifier )
43
+ return streamHandler ( stream )
44
+ } )
45
+ . catch ( err => {
46
+ if ( err . code === 'EINTEGRITY' ) {
47
+ opts . log . warn ( 'pacote' , `EINTEGRITY while extracting ${ spec } from ${ file } .You will have to recreate the file.` )
48
+ opts . log . verbose ( 'pacote' , `EINTEGRITY for ${ spec } : ${ err . message } ` )
49
+ }
50
+ throw err
51
+ } )
51
52
} )
52
- } )
53
- : BB . reject ( Object . assign ( new Error ( 'no file!' ) , { code : 'ENOENT' } ) )
53
+ : BB . reject ( Object . assign ( new Error ( 'no file!' ) , { code : 'ENOENT' } ) )
54
54
55
55
const tryDigest = tryFile
56
- . catch ( err => {
57
- if (
58
- opts . preferOnline ||
56
+ . catch ( err => {
57
+ if (
58
+ opts . preferOnline ||
59
59
! opts . cache ||
60
60
! opts . integrity ||
61
61
! RETRIABLE_ERRORS . has ( err . code )
62
- ) {
63
- throw err
64
- } else {
65
- opts . log . silly ( 'tarball' , `trying ${ spec } by hash: ${ opts . integrity } ` )
66
- const stream = cacache . get . stream . byDigest (
67
- opts . cache , opts . integrity , opts
68
- )
69
- stream . once ( 'error' , err => stream . on ( 'newListener' , ( ev , l ) => {
70
- if ( ev === 'error' ) { l ( err ) }
71
- } ) )
72
- return streamHandler ( stream )
73
- . catch ( err => {
74
- if ( err . code === 'EINTEGRITY' || err . code === 'Z_DATA_ERROR' ) {
75
- opts . log . warn ( 'tarball' , `cached data for ${ spec } (${ opts . integrity } ) seems to be corrupted. Refreshing cache.` )
76
- return cleanUpCached ( opts . cache , opts . integrity , opts )
77
- . then ( ( ) => { throw err } )
78
- } else {
79
- throw err
80
- }
81
- } )
82
- }
83
- } )
62
+ ) {
63
+ throw err
64
+ } else {
65
+ opts . log . silly ( 'tarball' , `trying ${ spec } by hash: ${ opts . integrity } ` )
66
+ const stream = cacache . get . stream . byDigest (
67
+ opts . cache , opts . integrity , opts
68
+ )
69
+ stream . once ( 'error' , err => stream . on ( 'newListener' , ( ev , l ) => {
70
+ if ( ev === 'error' ) { l ( err ) }
71
+ } ) )
72
+ return streamHandler ( stream )
73
+ . catch ( err => {
74
+ if ( err . code === 'EINTEGRITY' || err . code === 'Z_DATA_ERROR' ) {
75
+ opts . log . warn ( 'tarball' , `cached data for ${ spec } (${ opts . integrity } ) seems to be corrupted. Refreshing cache.` )
76
+ return cleanUpCached ( opts . cache , opts . integrity , opts )
77
+ . then ( ( ) => { throw err } )
78
+ } else {
79
+ throw err
80
+ }
81
+ } )
82
+ }
83
+ } )
84
84
85
85
const trySpec = tryDigest
86
- . catch ( err => {
87
- if ( ! RETRIABLE_ERRORS . has ( err . code ) ) {
86
+ . catch ( err => {
87
+ if ( ! RETRIABLE_ERRORS . has ( err . code ) ) {
88
88
// If it's not one of our retriable errors, bail out and give up.
89
- throw err
90
- } else {
91
- opts . log . silly (
92
- 'tarball' ,
93
- `no local data for ${ spec } . Extracting by manifest.`
94
- )
95
- return BB . resolve ( retry ( ( tryAgain , attemptNum ) => {
96
- const tardata = fetch . tarball ( spec , opts )
97
- if ( ! opts . resolved ) {
98
- tardata . on ( 'manifest' , m => {
99
- opts . resolved = m . _resolved
100
- } )
101
- tardata . on ( 'integrity' , i => {
102
- opts . integrity = i
103
- } )
104
- }
105
- return BB . try ( ( ) => streamHandler ( tardata ) )
106
- . catch ( err => {
107
- // Retry once if we have a cache, to clear up any weird conditions.
108
- // Don't retry network errors, though -- make-fetch-happen has already
109
- // taken care of making sure we're all set on that front.
110
- if ( opts . cache && err . code && ! err . code . match ( / ^ E \d { 3 } $ / ) ) {
111
- if ( err . code === 'EINTEGRITY' || err . code === 'Z_DATA_ERROR' ) {
112
- opts . log . warn ( 'tarball' , `tarball data for ${ spec } (${ opts . integrity } ) seems to be corrupted. Trying one more time.` )
113
- }
114
- return cleanUpCached ( opts . cache , err . sri , opts )
115
- . then ( ( ) => tryAgain ( err ) )
116
- } else {
117
- throw err
89
+ throw err
90
+ } else {
91
+ opts . log . silly (
92
+ 'tarball' ,
93
+ `no local data for ${ spec } . Extracting by manifest.`
94
+ )
95
+ return BB . resolve ( retry ( ( tryAgain , attemptNum ) => {
96
+ const tardata = fetch . tarball ( spec , opts )
97
+ if ( ! opts . resolved ) {
98
+ tardata . on ( 'manifest' , m => {
99
+ opts . resolved = m . _resolved
100
+ } )
101
+ tardata . on ( 'integrity' , i => {
102
+ opts . integrity = i
103
+ } )
118
104
}
119
- } )
120
- } , { retries : 1 } ) )
121
- }
122
- } )
105
+ return BB . try ( ( ) => streamHandler ( tardata ) )
106
+ . catch ( err => {
107
+ // Retry once if we have a cache, to clear up any weird conditions.
108
+ // Don't retry network errors, though -- make-fetch-happen has already
109
+ // taken care of making sure we're all set on that front.
110
+ if ( opts . cache && err . code && ! err . code . match ( / ^ E \d { 3 } $ / ) ) {
111
+ if ( err . code === 'EINTEGRITY' || err . code === 'Z_DATA_ERROR' ) {
112
+ opts . log . warn ( 'tarball' , `tarball data for ${ spec } (${ opts . integrity } ) seems to be corrupted. Trying one more time.` )
113
+ }
114
+ return cleanUpCached ( opts . cache , err . sri , opts )
115
+ . then ( ( ) => tryAgain ( err ) )
116
+ } else {
117
+ throw err
118
+ }
119
+ } )
120
+ } , { retries : 1 } ) )
121
+ }
122
+ } )
123
123
124
124
return trySpec
125
- . catch ( err => {
126
- if ( err . code === 'EINTEGRITY' ) {
127
- err . message = `Verification failed while extracting ${ spec } :\n${ err . message } `
128
- }
129
- throw err
130
- } )
125
+ . catch ( err => {
126
+ if ( err . code === 'EINTEGRITY' ) {
127
+ err . message = `Verification failed while extracting ${ spec } :\n${ err . message } `
128
+ }
129
+ throw err
130
+ } )
131
131
}
132
132
133
133
function cleanUpCached ( cachePath , integrity , opts ) {
0 commit comments