Skip to content

Commit

Permalink
Merge pull request #1651 from codefori/fix/sourceASPonSysbas
Browse files Browse the repository at this point in the history
Look for member on SYSBAS if config.sourceASP is set
  • Loading branch information
sebjulliand authored Nov 18, 2023
2 parents 9843e2d + ab753f4 commit ec8a4dc
Showing 1 changed file with 58 additions and 30 deletions.
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

0 comments on commit ec8a4dc

Please sign in to comment.