Skip to content

Commit

Permalink
fix: store cached encoding by URI path instead of label/short path (#…
Browse files Browse the repository at this point in the history
…3363)

* fix: store DS encoding by URI path instead of DS name

Signed-off-by: Trae Yelovich <[email protected]>

* fix failing test, update changelog

Signed-off-by: Trae Yelovich <[email protected]>

* use resourceUri path in USS encoding map

Signed-off-by: Trae Yelovich <[email protected]>

* chore: fix inconsistency in changelog

Signed-off-by: Trae Yelovich <[email protected]>

* use resourceUri in SharedUtils tests

Signed-off-by: Trae Yelovich <[email protected]>

---------

Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok authored Dec 17, 2024
1 parent 080a8d9 commit aea6d92
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed an issue where data set nodes did not update if migrated or recalled outside of Zowe Explorer. [#3294](https://github.com/zowe/zowe-explorer-vscode/issues/3294)
- Fixed an issue where listing data sets resulted in an error after opening a data set with an encoding. [#3347](https://github.com/zowe/zowe-explorer-vscode/issues/3347)
- Fixed an issue where binary USS files were not fetched using the "Pull from Mainframe" context menu option. [#3355](https://github.com/zowe/zowe-explorer-vscode/issues/3355)
- Fixed an issue where cached encoding was applied for all profiles with the same data set or USS path in the "Open with Encoding" menu. [#3363](https://github.com/zowe/zowe-explorer-vscode/pull/3363)

## `3.0.3`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ describe("Shared utils unit tests - function promptForEncoding", () => {
profile: blockMocks.profile,
parentNode: sessionNode,
});
DatasetFSProvider.instance.encodingMap["TEST.PS"] = { kind: "text" };
DatasetFSProvider.instance.encodingMap[node.resourceUri?.path] = { kind: "text" };
blockMocks.getEncodingForFile.mockReturnValueOnce(undefined);
await SharedUtils.promptForEncoding(node);
expect(blockMocks.showQuickPick).toHaveBeenCalled();
Expand Down Expand Up @@ -555,7 +555,7 @@ describe("Shared utils unit tests - function promptForEncoding", () => {
spool: createIJobFile(),
parentNode: jobNode,
});
JobFSProvider.instance.encodingMap[spoolNode.resourceUri.path] = { kind: "text" };
JobFSProvider.instance.encodingMap[spoolNode.resourceUri?.path] = { kind: "text" };
blockMocks.getEncodingForFile.mockReturnValueOnce(undefined);
await SharedUtils.promptForEncoding(spoolNode);
expect(blockMocks.showQuickPick).toHaveBeenCalled();
Expand Down Expand Up @@ -694,7 +694,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(node, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(node);

expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri.path);
expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -720,7 +720,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(node, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(node);

expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri.path);
expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -746,7 +746,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(node, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(node);

expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri.path);
expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri?.path);
expect(response).toEqual(encoding.codepage);
});

Expand All @@ -772,7 +772,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(node, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(node);

expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri.path);
expect(encodingMapSpy).toHaveBeenCalledWith(node.resourceUri?.path);
expect(response).toEqual(encoding);
});
});
Expand All @@ -793,7 +793,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(ussNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(ussNode);

expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.fullPath);
expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -812,7 +812,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(ussNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(ussNode);

expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.fullPath);
expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -831,7 +831,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(ussNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(ussNode);

expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.fullPath);
expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.resourceUri?.path);
expect(response).toEqual(encoding.codepage);
});

Expand All @@ -850,7 +850,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(ussNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(ussNode);

expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.fullPath);
expect(encodingMapSpy).toHaveBeenCalledWith(ussNode.resourceUri?.path);
expect(response).toEqual(encoding);
});
});
Expand All @@ -872,7 +872,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(dsNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(dsNode);

expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.label);
expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -891,7 +891,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(dsNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(dsNode);

expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.label);
expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -910,7 +910,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(dsNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(dsNode);

expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.label);
expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.resourceUri?.path);
expect(response).toEqual(encoding.codepage);
});

Expand All @@ -929,7 +929,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(dsNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(dsNode);

expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.label);
expect(encodingMapSpy).toHaveBeenCalledWith(dsNode.resourceUri?.path);
expect(response).toEqual(encoding);
});
});
Expand Down Expand Up @@ -958,7 +958,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(memNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(memNode);

expect(encodingMapSpy).toHaveBeenCalledWith(`${dsNode.label as string}(${memNode.label as string})`);
expect(encodingMapSpy).toHaveBeenCalledWith(memNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -985,7 +985,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(memNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(memNode);

expect(encodingMapSpy).toHaveBeenCalledWith(`${dsNode.label as string}(${memNode.label as string})`);
expect(encodingMapSpy).toHaveBeenCalledWith(memNode.resourceUri?.path);
expect(response).toEqual(encoding.kind);
});

Expand All @@ -1012,7 +1012,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(memNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(memNode);

expect(encodingMapSpy).toHaveBeenCalledWith(`${dsNode.label as string}(${memNode.label as string})`);
expect(encodingMapSpy).toHaveBeenCalledWith(memNode.resourceUri?.path);
expect(response).toEqual(encoding.codepage);
});

Expand All @@ -1039,7 +1039,7 @@ describe("Shared utils unit tests - function getCachedEncoding", () => {
const encodingMapSpy = jest.spyOn(memNode, "getEncodingInMap").mockResolvedValue(encoding);
const response = await SharedUtils.getCachedEncoding(memNode);

expect(encodingMapSpy).toHaveBeenCalledWith(`${dsNode.label as string}(${memNode.label as string})`);
expect(encodingMapSpy).toHaveBeenCalledWith(memNode.resourceUri?.path);
expect(response).toEqual(encoding);
});
});
Expand Down
5 changes: 2 additions & 3 deletions packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,10 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
} else {
DatasetFSProvider.instance.makeEmptyDsWithEncoding(this.resourceUri, encoding);
}
const fullPath = isMemberNode ? `${this.getParent().label as string}(${this.label as string})` : (this.label as string);
if (encoding != null) {
this.updateEncodingInMap(fullPath, encoding);
this.updateEncodingInMap(this.resourceUri.path, encoding);
} else {
delete DatasetFSProvider.instance.encodingMap[fullPath];
delete DatasetFSProvider.instance.encodingMap[this.resourceUri.path];
}
if (this.getParent() && this.getParent().contextValue === Constants.FAV_PROFILE_CONTEXT) {
this.contextValue += Constants.FAV_SUFFIX;
Expand Down
6 changes: 2 additions & 4 deletions packages/zowe-explorer/src/trees/shared/SharedUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,11 @@ export class SharedUtils {
public static async getCachedEncoding(node: IZoweTreeNode): Promise<string | undefined> {
let cachedEncoding: ZosEncoding;
if (SharedUtils.isZoweUSSTreeNode(node)) {
cachedEncoding = await node.getEncodingInMap(node.fullPath);
cachedEncoding = await node.getEncodingInMap(node.resourceUri.path);
} else if (SharedUtils.isZoweJobTreeNode(node)) {
cachedEncoding = await node.getEncodingInMap(node.resourceUri.path);
} else {
const isMemberNode = node.contextValue.startsWith(Constants.DS_MEMBER_CONTEXT);
const dsKey = isMemberNode ? `${node.getParent().label as string}(${node.label as string})` : (node.label as string);
cachedEncoding = await (node as IZoweDatasetTreeNode).getEncodingInMap(dsKey);
cachedEncoding = await (node as IZoweDatasetTreeNode).getEncodingInMap(node.resourceUri.path);
}
return cachedEncoding?.kind === "other" ? cachedEncoding.codepage : cachedEncoding?.kind;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer/src/trees/uss/ZoweUSSNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ export class ZoweUSSNode extends ZoweTreeNode implements IZoweUSSTreeNode {
}
UssFSProvider.instance.setEncodingForFile(this.resourceUri, encoding);
if (encoding != null) {
this.updateEncodingInMap(this.fullPath, encoding);
this.updateEncodingInMap(this.resourceUri.path, encoding);
} else {
delete UssFSProvider.instance.encodingMap[this.fullPath];
delete UssFSProvider.instance.encodingMap[this.resourceUri.path];
}
if (this.getParent() && this.getParent().contextValue === Constants.FAV_PROFILE_CONTEXT) {
this.contextValue =
Expand Down

0 comments on commit aea6d92

Please sign in to comment.