mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Install: avoid race conditions when creating directories (#1358)
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user