From 8944fe323c75c92f5e8ea792288cc1ac277b0e54 Mon Sep 17 00:00:00 2001 From: Karan Patel <17771013+KaranP25@users.noreply.github.com> Date: Tue, 18 Feb 2025 16:20:08 -0500 Subject: [PATCH] fix to use profile encoding rather than metadata encoding during upload and download of dataset and uss files (#3457) * update to use profile encoding rather than metadata encoding for fetching and uploading datasets or uss files Signed-off-by: Karan * update to changelog Signed-off-by: Karan * test fix after new changes Signed-off-by: Karan * update to changelog Signed-off-by: Karan * cut down on the duplication code in test fix Signed-off-by: Karan --------- Signed-off-by: Karan Signed-off-by: Karan Signed-off-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> Co-authored-by: Karan Co-authored-by: Karan Co-authored-by: Billie Simmons Co-authored-by: Fernando Rijo Cedeno <37381190+zFernand0@users.noreply.github.com> --- packages/zowe-explorer/CHANGELOG.md | 2 ++ .../trees/dataset/DatasetFSProvider.unit.test.ts | 12 ++++++++++++ .../__unit__/trees/uss/UssFSProvider.unit.test.ts | 11 +++++++++++ .../src/trees/dataset/DatasetFSProvider.ts | 6 ++++-- .../zowe-explorer/src/trees/uss/UssFSProvider.ts | 6 ++++-- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/zowe-explorer/CHANGELOG.md b/packages/zowe-explorer/CHANGELOG.md index d7065510e6..ca9d96b341 100644 --- a/packages/zowe-explorer/CHANGELOG.md +++ b/packages/zowe-explorer/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen - Fixed an issue where the 'Delete' key binding for the USS tree returns a 'contextValue' error. [#2796](https://github.com/zowe/zowe-explorer-vscode/issues/2796) - Fixed an issue where cancelling Unix, MVS or TSO command still submits the command. [#3422](https://github.com/zowe/zowe-explorer-vscode/issues/3422) - Fixed an issue where user is unable to open a renamed sequential data set from the Data Sets tree view.. [#3345](https://github.com/zowe/zowe-explorer-vscode/issues/3345) +- Fixed an issue seen with outdated profile information in the z/OS tree view data during upload and download of data set and USS files + [#3457](https://github.com/zowe/zowe-explorer-vscode/issues/3457) - Fixed issue where deleting too many nodes at once would cause the confirmation prompt to be oversized. [#3254](https://github.com/zowe/zowe-explorer-vscode/issues/3254) ## `3.1.1` diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetFSProvider.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetFSProvider.unit.test.ts index 63d639c1bc..f469c69573 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetFSProvider.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetFSProvider.unit.test.ts @@ -27,6 +27,7 @@ import { import { MockedProperty } from "../../../__mocks__/mockUtils"; import { DatasetFSProvider } from "../../../../src/trees/dataset/DatasetFSProvider"; import { ZoweExplorerApiRegister } from "../../../../src/extending/ZoweExplorerApiRegister"; +import { Profiles } from "../../../../src/configuration/Profiles"; import { AuthUtils } from "../../../../src/utils/AuthUtils"; import * as path from "path"; const dayjs = require("dayjs"); @@ -202,6 +203,17 @@ describe("readDirectory", () => { }); }); describe("fetchDatasetAtUri", () => { + beforeEach(() => { + Object.defineProperty(Profiles, "getInstance", { + value: jest.fn(() => { + return { + loadNamedProfile: jest.fn(() => { + return testProfile; + }), + }; + }), + }); + }); it("fetches a data set at the given URI", async () => { const contents = "dataset contents"; const mockMvsApi = { diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/uss/UssFSProvider.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/uss/UssFSProvider.unit.test.ts index 9fde97d3ef..6e3180f647 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/uss/UssFSProvider.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/uss/UssFSProvider.unit.test.ts @@ -325,6 +325,17 @@ describe("readDirectory", () => { }); describe("fetchFileAtUri", () => { + beforeEach(() => { + Object.defineProperty(Profiles, "getInstance", { + value: jest.fn(() => { + return { + loadNamedProfile: jest.fn(() => { + return testProfile; + }), + }; + }), + }); + }); it("calls getContents to get the data for a file entry", async () => { const fileEntry = { ...testEntries.file }; const lookupAsFileMock = jest.spyOn((UssFSProvider as any).prototype, "_lookupAsFile").mockReturnValueOnce(fileEntry); diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts b/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts index d9bb0a6cdd..260f4b002c 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts @@ -382,7 +382,8 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem let dsEntry = this._lookupAsFile(uri, { silent: true }) as DsEntry | undefined; const bufBuilder = new BufferBuilder(); const metadata = dsEntry?.metadata ?? this._getInfoFromUri(uri); - const profileEncoding = dsEntry?.encoding ? null : dsEntry?.metadata.profile.profile?.encoding; + const profile = Profiles.getInstance().loadNamedProfile(dsEntry?.metadata.profile.name); + const profileEncoding = dsEntry?.encoding ? null : profile.profile?.encoding; // use profile encoding rather than metadata encoding try { await AuthHandler.waitForUnlock(metadata.profile); const resp = await ZoweExplorerApiRegister.getMvsApi(metadata.profile).getContents(metadata.dsName, { @@ -510,7 +511,8 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem let resp: IZosFilesResponse; try { const mvsApi = ZoweExplorerApiRegister.getMvsApi(entry.metadata.profile); - const profileEncoding = entry.encoding ? null : entry.metadata.profile.profile?.encoding; + const profile = Profiles.getInstance().loadNamedProfile(entry?.metadata.profile.name); + const profileEncoding = entry.encoding ? null : profile.profile?.encoding; // use profile encoding rather than metadata encoding resp = await mvsApi.uploadFromBuffer(Buffer.from(content), entry.metadata.dsName, { binary: entry.encoding?.kind === "binary", encoding: entry.encoding?.kind === "other" ? entry.encoding.codepage : profileEncoding, diff --git a/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts b/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts index 389e5ab08e..c659544947 100644 --- a/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts +++ b/packages/zowe-explorer/src/trees/uss/UssFSProvider.ts @@ -279,7 +279,8 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv let resp: IZosFilesResponse; try { await this.autoDetectEncoding(file as UssFile); - const profileEncoding = file.encoding ? null : file.metadata.profile.profile?.encoding; + const profile = Profiles.getInstance().loadNamedProfile(file?.metadata.profile.name); + const profileEncoding = file.encoding ? null : profile.profile?.encoding; // use profile encoding rather than metadata encoding await AuthHandler.waitForUnlock(file.metadata.profile); resp = await ZoweExplorerApiRegister.getUssApi(metadata.profile).getContents(filePath, { binary: file.encoding?.kind === "binary", @@ -408,7 +409,8 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv try { const ussApi = ZoweExplorerApiRegister.getUssApi(entry.metadata.profile); await this.autoDetectEncoding(entry); - const profileEncoding = entry.encoding ? null : entry.metadata.profile.profile?.encoding; + const profile = Profiles.getInstance().loadNamedProfile(entry?.metadata.profile.name); + const profileEncoding = entry.encoding ? null : profile.profile?.encoding; // use profile encoding rather than metadata encoding resp = await ussApi.uploadFromBuffer(Buffer.from(content), entry.metadata.path, { binary: entry.encoding?.kind === "binary",