Skip to content

Commit

Permalink
Handle mkdirp throwing eexist
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Jun 20, 2024
1 parent 7e1d67d commit 2522f26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
18 changes: 9 additions & 9 deletions lib/initInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@ const versionLocation = path.join(destination, 'component.json');
config.productDir = path.join(__dirname, '..', 'defaults');

//Begin generate any missing folders
fs.mkdirSync(destination, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(destination, initUtils.FOLDER_MODE);

if (!config.siteDir) {
config.siteDir = path.join(destination, 'site');
}
const sitePluginStorage = path.join(config.siteDir, 'ZLUX', 'pluginStorage');
fs.mkdirSync(sitePluginStorage, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(sitePluginStorage, initUtils.FOLDER_MODE);

if (!config.instanceDir) {
config.instanceDir = destination;
}
const instancePluginStorage = path.join(config.instanceDir, 'ZLUX', 'pluginStorage');
fs.mkdirSync(instancePluginStorage, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(instancePluginStorage, initUtils.FOLDER_MODE);
const recognizersPluginStorage = path.join(config.instanceDir, 'ZLUX/pluginStorage', 'org.zowe.zlux.ng2desktop/recognizers');
fs.mkdirSync(recognizersPluginStorage, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(recognizersPluginStorage, initUtils.FOLDER_MODE);
const actionsPluginStorage = path.join(config.instanceDir, 'ZLUX/pluginStorage/org.zowe.zlux.ng2desktop', 'actions');
fs.mkdirSync(actionsPluginStorage, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(actionsPluginStorage, initUtils.FOLDER_MODE);

const instanceConfig = path.join(config.instanceDir, 'serverConfig');
//750 specifically, to keep server config secure
fs.mkdirSync(instanceConfig, {mode: 0o0750});
initUtils.mkdirp(instanceConfig, 0o0750});

if (!config.groupsDir) {
config.groupsDir = path.join(config.instanceDir, 'groups');
}
fs.mkdirSync(config.groupsDir, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(config.groupsDir, initUtils.FOLDER_MODE);

if (!config.usersDir) {
config.usersDir = path.join(config.instanceDir, 'users');
}
fs.mkdirSync(config.usersDir, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(config.usersDir, initUtils.FOLDER_MODE);

if (!config.pluginsDir) {
config.pluginsDir = path.join(destination, 'plugins');
}

fs.mkdirSync(config.pluginsDir, {mode: initUtils.FOLDER_MODE, recursive: true});
initUtils.mkdirp(config.pluginsDir, initUtils.FOLDER_MODE);

function generateComponentJson() {
let componentJsonContent;
Expand Down
14 changes: 12 additions & 2 deletions lib/initUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ module.exports.registerBundledPlugins = function(destination, configDestination,
});
}

function mkdirp(directory, mode) {
try {
fs.mkdirSync(directory, {mode: mode, recursive: true});
} catch (e) {
if (e.code != 'EEXIST') {
throw e;
}
}
}
module.exports.mkdirp = mkdirp;


function printFormattedMessage(level, message) {
Expand Down Expand Up @@ -313,7 +323,7 @@ module.exports.registerBundledPlugin = registerBundledPlugin;
module.exports.setTerminalDefaults = function(configDestination, instanceItems) {
if (instanceItems.indexOf('org.zowe.terminal.vt.json') != -1) {
let defaultConfigDir = path.join(configDestination,'org.zowe.terminal.vt','sessions');
fs.mkdirSync(defaultConfigDir, {recursive: true});
mkdirp(defaultConfigDir);
try {
fs.writeFileSync(path.join(defaultConfigDir,'_defaultVT.json'),
JSON.stringify({host:process.env['ZWED_SSH_HOST'] ? process.env['ZWED_SSH_HOST'] : "",
Expand All @@ -329,7 +339,7 @@ module.exports.setTerminalDefaults = function(configDestination, instanceItems)
security = process.env['ZWED_TN3270_SECURITY'];
}
let defaultConfigDir = path.join(configDestination,'org.zowe.terminal.tn3270','sessions');
fs.mkdirSync(defaultConfigDir, {recursive: true});
mkdirp(defaultConfigDir);
try {
let tn3270Json = {host:process.env['ZWED_TN3270_HOST'] ? process.env['ZWED_TN3270_HOST'] : "",
port: process.env['ZWED_TN3270_PORT'] ? process.env['ZWED_TN3270_PORT'] : 23,
Expand Down

0 comments on commit 2522f26

Please sign in to comment.