Skip to content

Commit

Permalink
refactor: check if maxLength exists before comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Jan 22, 2025
1 parent 2adf7d3 commit 6dff86a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/zosfiles/src/methods/list/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,18 @@ export class List {
ImperativeExpect.toNotBeEqual(patterns.length, 0, ZosFilesMessages.missingPatterns.message);
const zosmfResponses: IZosmfListResponse[] = [];

const maxLength = options.maxLength;

let totalCount = 0;
// Get names of all data sets
for (const pattern of patterns) {
if (maxLength && totalCount >= options.maxLength) {
break;
}
let response: any;
try {
response = await List.dataSet(session, pattern, { attributes: true, maxLength: options.maxLength, start: options.start });
response = await List.dataSet(session, pattern,
{ attributes: true, maxLength: maxLength ? maxLength - totalCount : undefined, start: options.start });
} catch (err) {
if (!(err instanceof ImperativeError && err.errorCode?.toString().startsWith("5"))) {
throw err;
Expand Down Expand Up @@ -472,6 +479,9 @@ export class List {
await asyncPool(maxConcurrentRequests, response.apiResponse.items, createListPromise);
}
}
if (response.success && response.apiResponse?.items?.length > 0) {
totalCount += response.apiResponse.items.length;
}
zosmfResponses.push(...response.apiResponse.items);
}

Expand Down

0 comments on commit 6dff86a

Please sign in to comment.