packager: do not use slashes in key

Summary: Internally we use `multipart/form-data` to upload transformed files to the global cache, using the keys as file names. Unfortunately the server would read that and consider only the basename as the key, not the full path. So we wouldn't store the data under the right key. This is definitely a bug in the way upload is implemented: we should transmit the keys separately. But, this changeset offers a quick mitigation by avoiding slashes in the key, so that the whole key is a valid base file name.

Reviewed By: davidaurelio

Differential Revision: D5087780

fbshipit-source-id: 9e4a698c1f57c4c3b91b56b43eef82c1c7dd862b
This commit is contained in:
Jean Lauliac 2017-05-18 11:40:38 -07:00 committed by Facebook Github Bot
parent 79ff67320f
commit 5bdaf4697d
2 changed files with 4 additions and 3 deletions

View File

@ -232,9 +232,10 @@ class URIBasedGlobalTransformCache {
hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions));
const cacheKey = props.getTransformCacheKey(transformOptions);
hash.update(JSON.stringify(cacheKey));
hash.update(JSON.stringify(localPath));
hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex'));
const digest = hash.digest('hex');
return `${digest}-${localPath}`;
return `${digest}-${path.basename(localPath)}`;
}
/**

View File

@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = `
Array [
Object {
"code": "/* code from http://globalcache.com/cd6df9b7e86839dafc5e9b5b493a28cbc55074e7-some/where/foo.js */",
"code": "/* code from http://globalcache.com/b23da8c74218e6155fcaf590a0fedbd1d117c2ae-foo.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},
Object {
"code": "/* code from http://globalcache.com/6329a317fcf94d74cc9a1de6442ee7c25e27a507-some/where/else/bar.js */",
"code": "/* code from http://globalcache.com/5e95f6c3e9bac0282480cda6f1a984ad8bc83e55-bar.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},