Skip to content

Commit 236d0eb

Browse files
authored
Merge pull request #1949 from chrjorgensen/fix/resolve-with-variants
Fix member and object resolve with variants
2 parents e1763db + 03afbf8 commit 236d0eb

File tree

2 files changed

+86
-18
lines changed

2 files changed

+86
-18
lines changed

src/api/IBMiContent.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -778,22 +778,24 @@ export default class IBMiContent {
778778
}
779779

780780
async memberResolve(member: string, files: QsysPath[]): Promise<IBMiMember | undefined> {
781+
const inAmerican = (s: string) => { return this.ibmi.sysNameInAmerican(s) };
782+
const inLocal = (s: string) => { return this.ibmi.sysNameInLocal(s) };
783+
781784
// Escape names for shell
782-
const pathList = this.ibmi.upperCaseName(
783-
files
784-
.map(file => {
785-
const asp = file.asp || this.config.sourceASP;
786-
if (asp && asp.length > 0) {
787-
return [
788-
Tools.qualifyPath(file.library, file.name, member, asp, true),
789-
Tools.qualifyPath(file.library, file.name, member, undefined, true)
790-
].join(` `);
791-
} else {
792-
return Tools.qualifyPath(file.library, file.name, member, undefined, true);
793-
}
794-
})
795-
.join(` `)
796-
);
785+
const pathList = files
786+
.map(file => {
787+
const asp = file.asp || this.config.sourceASP;
788+
if (asp && asp.length > 0) {
789+
return [
790+
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), asp, true),
791+
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true)
792+
].join(` `);
793+
} else {
794+
return Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true);
795+
}
796+
})
797+
.join(` `)
798+
.toUpperCase();
797799

798800
const command = `for f in ${pathList}; do if [ -f $f ]; then echo $f; break; fi; done`;
799801
const result = await this.ibmi.sendCommand({
@@ -805,7 +807,7 @@ export default class IBMiContent {
805807

806808
if (firstMost) {
807809
try {
808-
const simplePath = Tools.unqualifyPath(firstMost);
810+
const simplePath = inLocal(Tools.unqualifyPath(firstMost));
809811

810812
// This can error if the path format is wrong for some reason.
811813
// Not that this would ever happen, but better to be safe than sorry
@@ -820,7 +822,7 @@ export default class IBMiContent {
820822
}
821823

822824
async objectResolve(object: string, libraries: string[]): Promise<string | undefined> {
823-
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.upperCaseName(lib)}.LIB/${this.ibmi.upperCaseName(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;
825+
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.sysNameInAmerican(lib)}.LIB/${this.ibmi.sysNameInAmerican(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;
824826

825827
const result = await this.ibmi.sendCommand({
826828
command,
@@ -830,7 +832,7 @@ export default class IBMiContent {
830832
const firstMost = result.stdout;
831833

832834
if (firstMost) {
833-
const lib = Tools.unqualifyPath(firstMost);
835+
const lib = this.ibmi.sysNameInLocal(Tools.unqualifyPath(firstMost));
834836

835837
return lib.split('/')[1];
836838
}

src/testing/content.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@ export const ContentSuite: TestSuite = {
5252
}
5353
},
5454

55+
{
56+
name: `Test memberResolve with variants`, test: async () => {
57+
const content = instance.getContent();
58+
const config = instance.getConfig();
59+
const connection = instance.getConnection();
60+
const tempLib = config!.tempLibrary,
61+
tempSPF = `O_ABC`.concat(connection!.variantChars.local),
62+
tempMbr = `O_ABC`.concat(connection!.variantChars.local);
63+
64+
const result = await connection!.runCommand({
65+
command: `CRTSRCPF ${tempLib}/${tempSPF} MBR(${tempMbr})`,
66+
environment: `ile`
67+
});
68+
69+
const member = await content?.memberResolve(tempMbr, [
70+
{ library: `QSYSINC`, name: `MIH` }, // Doesn't exist here
71+
{ library: `NOEXIST`, name: `SUP` }, // Doesn't exist here
72+
{ library: tempLib, name: tempSPF } // Doesn't exist here
73+
]);
74+
75+
assert.deepStrictEqual(member, {
76+
asp: undefined,
77+
library: tempLib,
78+
file: tempSPF,
79+
name: tempMbr,
80+
extension: `MBR`,
81+
basename: `${tempMbr}.MBR`
82+
});
83+
84+
// Cleanup...
85+
await connection!.runCommand({
86+
command: `DLTF ${tempLib}/${tempSPF}`,
87+
environment: `ile`
88+
});
89+
}
90+
},
91+
5592
{
5693
name: `Test memberResolve with bad name`, test: async () => {
5794
const content = instance.getContent();
@@ -92,6 +129,35 @@ export const ContentSuite: TestSuite = {
92129
}
93130
},
94131

132+
{
133+
name: `Test objectResolve .DTAARA with variants`, test: async () => {
134+
const content = instance.getContent();
135+
const config = instance.getConfig();
136+
const connection = instance.getConnection();
137+
const tempLib = config!.tempLibrary,
138+
tempObj = `O_ABC`.concat(connection!.variantChars.local);
139+
140+
await connection!.runCommand({
141+
command: `CRTDTAARA ${tempLib}/${tempObj} TYPE(*CHAR)`,
142+
environment: `ile`
143+
});
144+
145+
const lib = await content?.objectResolve(tempObj, [
146+
"QSYSINC", // Doesn't exist here
147+
"QSYS2", // Doesn't exist here
148+
tempLib // Does exist here
149+
]);
150+
151+
assert.strictEqual(lib, tempLib);
152+
153+
// Cleanup...
154+
await connection!.runCommand({
155+
command: `DLTDTAARA ${tempLib}/${tempObj}`,
156+
environment: `ile`
157+
});
158+
}
159+
},
160+
95161
{
96162
name: `Test objectResolve with bad name`, test: async () => {
97163
const content = instance.getContent();

0 commit comments

Comments
 (0)