From 1e6bca22db6d43478da910543a800e641f96335d Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Fri, 28 Apr 2017 09:17:59 -0700 Subject: [PATCH] packager: TransformCache: include UID + do not use base64 Summary: Two things in there: * Using `base64` was kinda broken, as it can contain slashes, invalid in file names. It would still work however because it would just create a second level folder when doing `mkdirp`. Still I think it's better to fix that correctness. * Include the UID in the hash, so that different users have different folders for sure, and that we reduce potiential permissions issues. `tmpdir()` already returns a folder that's user-specific on OS X, but this is not a guarantee on all platforms. Reviewed By: cpojer Differential Revision: D4969856 fbshipit-source-id: 4a9be35104ac9698edf2c84c58d395ee171ce2a8 --- packager/src/lib/TransformCache.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packager/src/lib/TransformCache.js b/packager/src/lib/TransformCache.js index 0defb875c..64d4c3dd2 100644 --- a/packager/src/lib/TransformCache.js +++ b/packager/src/lib/TransformCache.js @@ -39,16 +39,17 @@ const CACHE_SUB_DIR = 'cache'; const getCacheDirPath = (function() { let dirPath; return function() { - if (dirPath == null) { - dirPath = path.join( - require('os').tmpdir(), - CACHE_NAME + '-' + crypto.createHash('sha1') - .update(__dirname).digest('base64'), - ); - require('debug')('RNP:TransformCache:Dir')( - `transform cache directory: ${dirPath}` - ); + if (dirPath != null) { + return dirPath; } + const hash = crypto.createHash('sha1').update(__dirname); + if (process.getuid != null) { + hash.update(process.getuid().toString()); + } + dirPath = path.join(require('os').tmpdir(), CACHE_NAME + '-' + hash.digest('hex')); + require('debug')('RNP:TransformCache:Dir')( + `transform cache directory: ${dirPath}` + ); return dirPath; }; })();