diff --git a/connect.js b/connect.js index 4aeba112..c46adc25 100644 --- a/connect.js +++ b/connect.js @@ -230,23 +230,22 @@ connect.setSSOParams = (config) => { }; connect.createDirectory = (dirname) => { - try { - const initDir = path.isAbsolute(dirname) ? path.sep : ''; - dirname.split(path.sep).reduce((parentDir, childDir) => { - const curDir = path.resolve(parentDir, childDir); - if (!fs.existsSync(curDir)) { - fs.mkdirSync(curDir); + const initDir = path.isAbsolute(dirname) ? path.sep : ''; + dirname.split(path.sep).reduce((parentDir, childDir) => { + const curDir = path.resolve(parentDir, childDir); + try { + fs.mkdirSync(curDir); + } catch (err) { + if (err.code !== 'EEXIST') { + if (err.code === 'ENOENT') { + throw new Error(`ENOENT: No such file or directory, mkdir '${dirname}'. Ensure that channel backup path separator is '${(platform === 'win32') ? '\\\\' : '/'}'`); + } else { + throw err; + } } - return curDir; - }, initDir); - } catch (err) { - if (err.code === 'EEXIST') { - return dirname; } - if (err.code === 'ENOENT') { - throw new Error(`ENOENT: No such file or directory, mkdir '${dirname}'. Ensure that channel backup path separator is '${(platform === 'win32') ? '\\\\' : '/'}'`); - } - } + return curDir; + }, initDir); } connect.readCookie = (cookieFile) => {