Install: avoid race conditions when creating directories (#1358)

This commit is contained in:
ajhool
2018-08-29 04:20:26 -04:00
committed by Lovell Fuller
parent 5bed3a7d52
commit bf3254cb16
5 changed files with 50 additions and 12 deletions

View File

@@ -15,15 +15,21 @@ const spawnSyncOptions = {
shell: true
};
const mkdirSync = function (dirPath) {
try {
fs.mkdirSync(dirPath);
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
};
const cachePath = function () {
const npmCachePath = env.npm_config_cache || (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
if (!fs.existsSync(npmCachePath)) {
fs.mkdirSync(npmCachePath);
}
mkdirSync(npmCachePath);
const libvipsCachePath = path.join(npmCachePath, '_libvips');
if (!fs.existsSync(libvipsCachePath)) {
fs.mkdirSync(libvipsCachePath);
}
mkdirSync(libvipsCachePath);
return libvipsCachePath;
};
@@ -78,5 +84,6 @@ module.exports = {
globalLibvipsVersion: globalLibvipsVersion,
hasVendoredLibvips: hasVendoredLibvips,
pkgConfigPath: pkgConfigPath,
useGlobalLibvips: useGlobalLibvips
useGlobalLibvips: useGlobalLibvips,
mkdirSync: mkdirSync
};