Skip to content

Commit

Permalink
Simplify JCL prinitng, isVsamDatasetExists bug
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Zeithaml <[email protected]>
  • Loading branch information
Martin-Zeithaml committed Feb 29, 2024
1 parent a4ffe30 commit 52eea1c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 4 additions & 5 deletions bin/commands/init/mvs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,16 @@ export function execute(allowOverwrite?: boolean) {
if (skippedDatasets && !allowOverwrite) {
common.printMessage(`Skipped writing to a dataset. To write, you must use --allow-overwrite.`);
} else {
const jcllibEscaped = stringlib.escapeDollar(jcllib);
if (allowOverwrite && needCleanup) {
zosJes.printAndHandleJcl(`//'${jcllibEscaped}(ZWERMVS)'`, `ZWERMVS`, jcllib, prefix, false, true);
zosJes.printAndHandleJcl(`//'${jcllib}(ZWERMVS)'`, `ZWERMVS`, jcllib, prefix, false, true);
}
if (allowOverwrite && needAuthCleanup) {
zosJes.printAndHandleJcl(`//'${jcllibEscaped}(ZWERMVS2)'`, `ZWERMVS2`, jcllib, prefix, false, true);
zosJes.printAndHandleJcl(`//'${jcllib}(ZWERMVS2)'`, `ZWERMVS2`, jcllib, prefix, false, true);
}

zosJes.printAndHandleJcl(`//'${jcllibEscaped}(ZWEIMVS)'`, `ZWEIMVS`, jcllib, prefix);
zosJes.printAndHandleJcl(`//'${jcllib}(ZWEIMVS)'`, `ZWEIMVS`, jcllib, prefix);
if (runALoadlibCreate === true) {
zosJes.printAndHandleJcl(`//'${jcllibEscaped}(ZWEIMVS2)'`, `ZWEIMVS2`, jcllib, prefix);
zosJes.printAndHandleJcl(`//'${jcllib}(ZWEIMVS2)'`, `ZWEIMVS2`, jcllib, prefix);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/commands/init/vsam/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function execute(allowOverwrite?: boolean, dryRun?: boolean, updateConfig
common.requireZoweYaml();
const ZOWE_CONFIG = config.getZoweConfig();

const cachingStorage = ZOWE_CONFIG.components['caching-service']?.storage?.mode;
const cachingStorage = ZOWE_CONFIG.components !== undefined ? ZOWE_CONFIG.components['caching-service']?.storage?.mode : undefined;
if (!cachingStorage || (cachingStorage.toUpperCase() != 'VSAM')) {
common.printError(`Warning ZWEL0301W: Zowe Caching Service is not configured to use VSAM. Command skipped.`);
return;
Expand Down
8 changes: 6 additions & 2 deletions bin/libs/zos-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import * as zoslib from './zos';
//TODO a bit of a hack. "cat" cant output a vsam, so it will always give errors.
// however, the errors it gives are different depending on if the vsam exists or not.
export function isVsamDatasetExists(datasetName: string): boolean {
const result = shell.execErrSync('sh', '-c', `cat "//'${datasetName}'" 1>/dev/null 2>&1`);
common.printTrace(` * isVsamDatasetExists: '${stringlib.escapeDollar(datasetName)}'`);
const result = shell.execErrSync('sh', '-c', `cat "//'${stringlib.escapeDollar(datasetName)}'" 1>/dev/null`);
return !(result.err && result.err.includes('EDC5049I'));
// EDC5049I = file not found
}

export function isDatasetExists(datasetName: string): boolean {
common.printTrace(` * isDatasetExists: '${stringlib.escapeDollar(datasetName)}'`);
const result = shell.execSync('sh', '-c', `cat "//'${stringlib.escapeDollar(datasetName)}'" 1>/dev/null 2>&1`);
return result.rc === 0;
}
Expand All @@ -35,6 +37,7 @@ export function isDatasetExists(datasetName: string): boolean {
// 1: data set is not in catalog
// 2: data set member doesn't exist
export function tsoIsDatasetExists(datasetName: string): number {
common.printTrace(` * tsoIsDatasetExists: '${stringlib.escapeDollar(datasetName)}'`);
const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(datasetName)}' label`);
if (result.rc != 0) {
if (result.out.includes('NOT IN CATALOG')) {
Expand All @@ -52,6 +55,7 @@ export function tsoIsDatasetExists(datasetName: string): number {
}

export function createDataSet(dsName: string, dsOptions: string): number {
common.printTrace(` * createDataSet: '${stringlib.escapeDollar(dsName)}' ${dsOptions}`);
const result=zoslib.tsoCommand(`ALLOCATE NEW DA('${stringlib.escapeDollar(dsName)}') ${dsOptions}`);
return result.rc;
}
Expand Down Expand Up @@ -81,7 +85,7 @@ export function copyToDataset(filePath: string, dsName: string, cpOptions: strin
}

export function getDatasetVolume(dataset: string): { rc: number, volume?: string } {
common.printTrace(`- Find volume of data set ${dataset}`);
common.printTrace(`- Find volume of data set ${stringlib.escapeDollar(dataset)}`);
const result = zoslib.tsoCommand(`listds '${stringlib.escapeDollar(dataset)}'`);
if (result.rc == 0) {
let volumesIndex = result.out.indexOf('--VOLUMES--');
Expand Down
2 changes: 1 addition & 1 deletion bin/libs/zos-jes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function waitForJob(jobid: string): {jobcctext?: string, jobcccode?: stri
}

export function printAndHandleJcl(jclLocationOrContent: string, jobName: string, jcllib: string, prefix: string, removeJclOnFinish?: boolean, continueOnFailure?: boolean, jclIsContent?: boolean){
const jclContents = jclIsContent ? jclLocationOrContent : shell.execOutSync('sh', '-c', `cat "${jclLocationOrContent}" 2>&1`).out;
const jclContents = jclIsContent ? jclLocationOrContent : shell.execOutSync('sh', '-c', `cat "${stringlib.escapeDollar(jclLocationOrContent)}" 2>&1`).out;

let jobHasFailures = false;
if (jclIsContent) {
Expand Down

0 comments on commit 52eea1c

Please sign in to comment.