diff options
author | isaacs <i@izs.me> | 2019-07-16 02:22:39 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2019-07-17 02:28:49 +0300 |
commit | 235e5d6df6f427585ec58425f1f3339d08f39d8a (patch) | |
tree | 89b24773c9db9e7b1e1cd8fd8884120b9392ad37 /lib/search | |
parent | 2c61ce65d6b67100fdf3fcb9729055b669cb1a1d (diff) |
search: ensure correct owner on all-packages metadata
Diffstat (limited to 'lib/search')
-rw-r--r-- | lib/search/all-package-metadata.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/search/all-package-metadata.js b/lib/search/all-package-metadata.js index 5883def5c..a006dadad 100644 --- a/lib/search/all-package-metadata.js +++ b/lib/search/all-package-metadata.js @@ -217,7 +217,7 @@ function extractUpdated (entryStream, label, opts) { // be output from it. module.exports._createCacheWriteStream = createCacheWriteStream function createCacheWriteStream (cacheFile, latest, opts) { - return _ensureCacheDirExists(cacheFile, opts).then(() => { + return _ensureCacheDirExists(cacheFile, opts).then(({uid, gid}) => { log.silly('all-package-metadata', 'creating output stream') const outStream = _createCacheOutStream() const cacheFileStream = writeStreamAtomic(cacheFile) @@ -231,19 +231,31 @@ function createCacheWriteStream (cacheFile, latest, opts) { let errEmitted = false linkStreams(inputStream, outStream, () => { errEmitted = true }) - cacheFileStream.on('close', () => !errEmitted && outStream.end()) + cacheFileStream.on('close', () => { + if (!errEmitted) { + if (typeof uid === 'number' && + typeof gid === 'number' && + process.getuid && + process.getgid && + (process.getuid() !== uid || process.getgid() !== gid)) { + chownr.sync(cacheFile, uid, gid) + } + outStream.end() + } + }) return ms.duplex.obj(inputStream, outStream) }) } +// return the {uid,gid} that the cache should have function _ensureCacheDirExists (cacheFile, opts) { var cacheBase = path.dirname(cacheFile) log.silly('all-package-metadata', 'making sure cache dir exists at', cacheBase) return correctMkdir(opts.cache).then(st => { return mkdir(cacheBase).then(made => { return chownr(made || cacheBase, st.uid, st.gid) - }) + }).then(() => ({ uid: st.uid, gid: st.gid })) }) } |