Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for member on SYSBAS if config.sourceASP is set #1651

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 58 additions & 30 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,40 +118,48 @@ export default class IBMiContent {
sourceFile = sourceFile.toUpperCase();
member = member.toUpperCase();

const path = Tools.qualifyPath(library, sourceFile, member, asp);
const tempRmt = this.getTempRemote(path);
const client = this.ibmi.client;

let retried = false;
let retry = 1;

while (retry > 0) {
retry--;
let retry = false;
let path = Tools.qualifyPath(library, sourceFile, member, asp);
const tempRmt = this.getTempRemote(path);
while (true) {
try {
//If this command fails we need to try again after we delete the temp remote
await this.ibmi.remoteCommand(
`CPYTOSTMF FROMMBR('${path}') TOSTMF('${tempRmt}') STMFOPT(*REPLACE) STMFCCSID(1208) DBFCCSID(${this.config.sourceFileCCSID})`, `.`
);
} catch (e) {
if (String(e).startsWith(`CPDA08A`)) {
if (!retried) {
await this.ibmi.sendCommand({ command: `rm -f ${tempRmt}`, directory: `.` });
retry++;
retried = true;
} else {
throw e;

if (!localPath) {
localPath = await tmpFile();
}
await client.getFile(localPath, tempRmt);
return await readFileAsync(localPath, `utf8`);
}
catch (e) {
if (!retry) {
const messageID = String(e).substring(0, 7);
switch (messageID) {
case "CPDA08A":
//We need to try again after we delete the temp remote
const result = await this.ibmi.sendCommand({ command: `rm -f ${tempRmt}`, directory: `.` });
retry = !result.code || result.code === 0;
break;
case "CPFA0A9":
//The member may be located on SYSBAS
if (asp) {
path = Tools.qualifyPath(library, sourceFile, member);
retry = true;
}
break;
default:
throw e;
}
} else {
}
else {
throw e;
}
}
}

if (!localPath) {
localPath = await tmpFile();
}
await client.getFile(localPath, tempRmt);
return await readFileAsync(localPath, `utf8`);
}

/**
Expand All @@ -164,19 +172,39 @@ export default class IBMiContent {
member = member.toUpperCase();

const client = this.ibmi.client;
const path = Tools.qualifyPath(library, sourceFile, member, asp);
const tempRmt = this.getTempRemote(path);
const tmpobj = await tmpFile();

let retry = false;
try {
await writeFileAsync(tmpobj, content, `utf8`);

let path = Tools.qualifyPath(library, sourceFile, member, asp);
const tempRmt = this.getTempRemote(path);
await client.putFile(tmpobj, tempRmt);
await this.ibmi.remoteCommand(
`QSYS/CPYFRMSTMF FROMSTMF('${tempRmt}') TOMBR('${path}') MBROPT(*REPLACE) STMFCCSID(1208) DBFCCSID(${this.config.sourceFileCCSID})`,
);

return true;
while (true) {
try {
await this.ibmi.remoteCommand(
`QSYS/CPYFRMSTMF FROMSTMF('${tempRmt}') TOMBR('${path}') MBROPT(*REPLACE) STMFCCSID(1208) DBFCCSID(${this.config.sourceFileCCSID})`,
);
return true;
}
catch (e) {
if (!retry) {
const messageID = String(e).substring(0, 7);
switch (messageID) {
case "CPFA0A9":
//The member may be located on SYSBAS
if (asp) {
path = Tools.qualifyPath(library, sourceFile, member);
retry = true;
}
break;
default:
throw e;
}
}
}
}
} catch (error) {
console.log(`Failed uploading member: ` + error);
return Promise.reject(error);
Expand Down