File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
const asyncMap = require ( 'slide/lib/async-map' )
4
4
const contentPath = require ( './content/path' )
5
+ const crypto = require ( 'crypto' )
5
6
const fixOwner = require ( './util/fix-owner' )
6
7
const fs = require ( 'graceful-fs' )
7
8
const lockfile = require ( 'lockfile' )
@@ -170,8 +171,17 @@ function indexPath (cache, key) {
170
171
171
172
module . exports . _hashKey = hashKey
172
173
function hashKey ( key ) {
173
- // relatively readable key. Conflicts handled by buckets.
174
- return key . replace ( / [ ^ a - z 0 - 9 _ - ] + / ig, '_' ) . toLowerCase ( ) . slice ( 0 , 120 )
174
+ // sha1 conflicts can be generated, but it doesn't matter in this case,
175
+ // since we intend for there to be regular conflicts anyway. You can have
176
+ // the entire cache in a single bucket and all that'll do is just make a big
177
+ // file with a lot of contention, if you can even pull it off in the `key`
178
+ // string. So whatever. `sha1` is faster and it doesn't trigger the warnings
179
+ // `md5` tends to (yet?...).
180
+ return crypto
181
+ . createHash ( 'sha1' )
182
+ . update ( key . toLowerCase ( ) ) // lump case-variant keys into same bucket.
183
+ . digest ( 'hex' )
184
+ . slice ( 0 , 7 )
175
185
}
176
186
177
187
function formatEntry ( cache , entry ) {
Original file line number Diff line number Diff line change @@ -141,8 +141,8 @@ test('key case-sensitivity', function (t) {
141
141
test ( 'hash conflict in same bucket' , function ( t ) {
142
142
// NOTE - this test will break if `index._hashKey` changes its algorithm.
143
143
// Adapt to it accordingly.
144
- const NEWKEY = KEY + '!'
145
- const CONFLICTING = KEY + '!!!'
144
+ const NEWKEY = KEY . toUpperCase ( )
145
+ const CONFLICTING = KEY . toLowerCase ( )
146
146
return index . insert (
147
147
CACHE , NEWKEY , DIGEST
148
148
) . then ( ( ) => (
@@ -157,7 +157,7 @@ test('hash conflict in same bucket', function (t) {
157
157
key : NEWKEY ,
158
158
digest : DIGEST
159
159
} , {
160
- key : KEY + '!!!' ,
160
+ key : CONFLICTING ,
161
161
digest : DIGEST
162
162
} ] , 'multiple entries for conflicting keys in the same bucket' )
163
163
} )
You can’t perform that action at this time.
0 commit comments