diff --git a/package.json b/package.json index b1c787253f..12cdab03be 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "packages/zowe-explorer/webviews/*" ], "engines": { - "vscode": "^1.79.0" + "vscode": "^1.63.0" }, "dependencies": { "@zowe/cli": "7.18.0", diff --git a/packages/zowe-explorer-ftp-extension/package.json b/packages/zowe-explorer-ftp-extension/package.json index 8865b07797..a2ed3709bb 100644 --- a/packages/zowe-explorer-ftp-extension/package.json +++ b/packages/zowe-explorer-ftp-extension/package.json @@ -45,7 +45,7 @@ "package": "vsce package --yarn && node ../../scripts/mv-pack.js zowe-explorer-ftp-extension vsix" }, "engines": { - "vscode": "^1.79.0" + "vscode": "^1.63.0" }, "dependencies": { "@zowe/zos-ftp-for-zowe-cli": "2.1.2", diff --git a/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts index d3c5eca4ec..d99dcee429 100644 --- a/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/dataset/init.unit.test.ts @@ -18,7 +18,6 @@ import * as sharedExtension from "../../../src/shared/init"; import { initDatasetProvider } from "../../../src/dataset/init"; import { Profiles } from "../../../src/Profiles"; import { IJestIt, ITestContext, processSubscriptions, spyOnSubscriptions } from "../../__common__/testUtils"; -import { ZoweLogger } from "../../../src/utils/LoggerUtils"; describe("Test src/dataset/extension", () => { describe("initDatasetProvider", () => { diff --git a/packages/zowe-explorer/__tests__/__unit__/uss/ZoweUSSNode.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/uss/ZoweUSSNode.unit.test.ts index 678149792a..0c206e03cd 100644 --- a/packages/zowe-explorer/__tests__/__unit__/uss/ZoweUSSNode.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/uss/ZoweUSSNode.unit.test.ts @@ -1078,7 +1078,7 @@ describe("ZoweUSSNode Unit Tests - Function node.openUSS()", () => { await node.openUSS(false, true, blockMocks.testUSSTree); expect(globalMocks.existsSync.mock.calls.length).toBe(1); expect(globalMocks.existsSync.mock.calls[0][0]).toBe(path.join(globals.USS_DIR, node.mProfileName || "", node.fullPath)); - expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Opening USS file..."); + expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Downloading USS file..."); // Tests that correct file is opened in editor globalMocks.withProgress(globalMocks.downloadUSSFile); @@ -1123,7 +1123,7 @@ describe("ZoweUSSNode Unit Tests - Function node.openUSS()", () => { await node.openUSS(false, true, blockMocks.testUSSTree); expect(globalMocks.existsSync.mock.calls.length).toBe(1); expect(globalMocks.existsSync.mock.calls[0][0]).toBe(path.join(globals.USS_DIR, node.mProfileName || "", node.fullPath)); - expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Opening USS file..."); + expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Downloading USS file..."); // Tests that correct file is opened in editor globalMocks.withProgress(globalMocks.downloadUSSFile); expect(globalMocks.withProgress).toBeCalledWith(globalMocks.downloadUSSFile); @@ -1275,7 +1275,7 @@ describe("ZoweUSSNode Unit Tests - Function node.openUSS()", () => { await node.openUSS(false, true, blockMocks.testUSSTree); expect(globalMocks.existsSync.mock.calls.length).toBe(1); expect(globalMocks.existsSync.mock.calls[0][0]).toBe(path.join(globals.USS_DIR, node.getProfileName() || "", node.fullPath)); - expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Opening USS file..."); + expect(globalMocks.setStatusBarMessage).toBeCalledWith("$(sync~spin) Downloading USS file..."); // Make sure correct file is displayed in the editor globalMocks.withProgress(globalMocks.downloadUSSFile); expect(globalMocks.openTextDocument.mock.calls.length).toBe(1); diff --git a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json index ec2afdf4b5..3764397531 100644 --- a/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/dataset/actions.i18n.json @@ -30,9 +30,9 @@ "createMember.creating": "Creating new data set member {0}", "createMember.error": "Unable to create member.", "dataSet.opening": "$(sync~spin) Opening data set...", - "openPS.error": "Invalid data set or member.", "dsActions.downloadPS.downloading.log": "Downloading {0}", "dsActions.downloadPS.downloading.message": "$(sync~spin) Downloading data set...", + "invalidDsMemberError.error": "Invalid data set or member.", "createFile.allocatingNewDataSet": "Attempting to allocate new data set", "handleUserSelection.qp.prompt": "Click on parameters to change them", "createFile.inputBox.placeHolder": "Name of Data Set", diff --git a/packages/zowe-explorer/i18n/sample/src/uss/ZoweUSSNode.i18n.json b/packages/zowe-explorer/i18n/sample/src/uss/ZoweUSSNode.i18n.json index 12ae0c3133..7039d361e2 100644 --- a/packages/zowe-explorer/i18n/sample/src/uss/ZoweUSSNode.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/uss/ZoweUSSNode.i18n.json @@ -8,9 +8,6 @@ "deleteUssPrompt.deleteCancelled": "Delete action was cancelled.", "deleteUSSNode.error.node": "Unable to delete node: ", "deleteUssNode.itemDeleted": "The item {0} has been deleted.", - "openUSS.error.invalidNode": "open() called from invalid node.", - "openUSS.name.exists": "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names", - "ussFile.opening": "$(sync~spin) Opening USS file...", "refreshUSS.error.invalidNode": "refreshUSS() called from invalid node.", "refreshUSS.error.notFound": "not found", "refreshUSS.file1": "Unable to find file: ", diff --git a/packages/zowe-explorer/i18n/sample/src/uss/actions.i18n.json b/packages/zowe-explorer/i18n/sample/src/uss/actions.i18n.json index a4af6ec483..6fa093f7c3 100644 --- a/packages/zowe-explorer/i18n/sample/src/uss/actions.i18n.json +++ b/packages/zowe-explorer/i18n/sample/src/uss/actions.i18n.json @@ -4,6 +4,9 @@ "createUSSNode.name": "Name of file or directory", "createUSSNode.name.exists": "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names.", "createUSSNode.error.create": "Unable to create node:", + "downloadUnixFile.invalidNode.error": "open() called from invalid node.", + "downloadUnixFile.name.exists": "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names", + "downloadUnixFile.downloading": "$(sync~spin) Downloading USS file...", "uploadFile.putContents": "Uploading USS file", "copyPath.infoMessage": "Copy Path is not yet supported in Theia.", "saveUSSFile.log.debug.saveRequest": "save requested for USS file ", diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index 5b48bb4882..928e011d82 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -1995,7 +1995,7 @@ "createDemoNodes": "ts-node ./scripts/createDemoNodes.ts" }, "engines": { - "vscode": "^1.79.0" + "vscode": "^1.63.0" }, "devDependencies": { "@napi-rs/cli": "^2.16.1", diff --git a/packages/zowe-explorer/src/dataset/DatasetTree.ts b/packages/zowe-explorer/src/dataset/DatasetTree.ts index 590b17d68a..0ffdd9c38c 100644 --- a/packages/zowe-explorer/src/dataset/DatasetTree.ts +++ b/packages/zowe-explorer/src/dataset/DatasetTree.ts @@ -237,7 +237,6 @@ export class DatasetTree extends ZoweTreeProvider implements IZoweTree { - let documentLabel: string; - const defaultMessage = localize("openPS.error", "Invalid data set or member."); +export async function downloadPS(node: api.IZoweDatasetTreeNode): Promise { + const fileInfo = {} as localFileInfo; switch (true) { // For favorited or non-favorited sequential DS: case contextually.isFavorite(node): case contextually.isSessionNotFav(node.getParent()): - documentLabel = node.label as string; + fileInfo.name = String(node.label); break; // For favorited or non-favorited data set members: case contextually.isFavoritePds(node.getParent()): case contextually.isPdsNotFav(node.getParent()): - documentLabel = String(node.getParent().getLabel()) + "(" + String(node.getLabel()) + ")"; + fileInfo.name = `${String(node.getParent().getLabel())}(${String(node.getLabel())})`; break; default: - api.Gui.errorMessage(defaultMessage); - throw Error(defaultMessage); + invalidDsMemberError(); } // if local copy exists, open that instead of pulling from mainframe - const documentFilePath = getDsDocumentFilePath(documentLabel, node); - if (!fs.existsSync(documentFilePath)) { - await downloadPS(node, documentFilePath, documentLabel); + fileInfo.path = getDsDocumentFilePath(fileInfo.name, node); + if (!fs.existsSync(fileInfo.path)) { + await downloadPsApiCall(node, fileInfo); } - return { documentLabel, documentFilePath }; + return fileInfo; } -async function downloadPS(node: api.IZoweDatasetTreeNode, documentFilePath: string, label: string): Promise { +async function downloadPsApiCall(node: api.IZoweDatasetTreeNode, fileInfo: localFileInfo): Promise { const prof = node.getProfile(); - ZoweLogger.info(localize("dsActions.downloadPS.downloading.log", "Downloading {0}", label)); + ZoweLogger.info(localize("dsActions.downloadPS.downloading.log", "Downloading {0}", fileInfo.name)); const statusMsg = api.Gui.setStatusBarMessage(localize("dsActions.downloadPS.downloading.message", "$(sync~spin) Downloading data set...")); - const response = await ZoweExplorerApiRegister.getMvsApi(prof).getContents(label, { - file: documentFilePath, + const response = await ZoweExplorerApiRegister.getMvsApi(prof).getContents(fileInfo.name, { + file: fileInfo.path, returnEtag: true, encoding: prof.profile?.encoding, responseTimeout: prof.profile?.responseTimeout, @@ -529,6 +528,12 @@ async function downloadPS(node: api.IZoweDatasetTreeNode, documentFilePath: stri statusMsg.dispose(); } +function invalidDsMemberError(): void { + const defaultMessage = localize("invalidDsMemberError.error", "Invalid data set or member."); + api.Gui.errorMessage(defaultMessage); + throw Error(defaultMessage); +} + export function getDataSetTypeAndOptions(type: string): { typeEnum: zowe.CreateDataSetTypeEnum; createOptions: vscode.WorkspaceConfiguration; diff --git a/packages/zowe-explorer/src/dataset/init.ts b/packages/zowe-explorer/src/dataset/init.ts index 82c60f4b5e..be75799c1d 100644 --- a/packages/zowe-explorer/src/dataset/init.ts +++ b/packages/zowe-explorer/src/dataset/init.ts @@ -23,7 +23,7 @@ import { ZoweLogger } from "../utils/LoggerUtils"; import { TreeViewUtils } from "../utils/TreeViewUtils"; export async function initDatasetProvider(context: vscode.ExtensionContext): Promise> { - ZoweLogger.trace("dataset.init.initDatasetProvider called."); + ZoweLogger.trace("Initializing the Data set provider."); const datasetProvider: IZoweTree = await createDatasetTree(); if (datasetProvider == null) { return null; diff --git a/packages/zowe-explorer/src/extension.ts b/packages/zowe-explorer/src/extension.ts index 9274ac6acd..e7538c5922 100644 --- a/packages/zowe-explorer/src/extension.ts +++ b/packages/zowe-explorer/src/extension.ts @@ -62,10 +62,9 @@ export async function activate(context: vscode.ExtensionContext): Promise boolean; } diff --git a/packages/zowe-explorer/src/shared/init.ts b/packages/zowe-explorer/src/shared/init.ts index 5937db3e23..2f387b3d8b 100644 --- a/packages/zowe-explorer/src/shared/init.ts +++ b/packages/zowe-explorer/src/shared/init.ts @@ -222,6 +222,7 @@ export function registerCommonCommands(context: vscode.ExtensionContext, provide return globals.FILE_SELECTED_TO_COMPARE; }) ); + globals.initializeFilesToCompare(); } } diff --git a/packages/zowe-explorer/src/shared/utils.ts b/packages/zowe-explorer/src/shared/utils.ts index f89bc6cacf..d8590150b6 100644 --- a/packages/zowe-explorer/src/shared/utils.ts +++ b/packages/zowe-explorer/src/shared/utils.ts @@ -21,12 +21,11 @@ import { IZosFilesResponse, imperative, IUploadOptions } from "@zowe/cli"; import { ZoweLogger } from "../utils/LoggerUtils"; import { isTypeUssTreeNode } from "./context"; import { markDocumentUnsaved } from "../utils/workspace"; -import { prepareDownloadPS } from "../dataset/actions"; -// import { downloadUnixFile, getUSSDocumentFilePath } from "../uss/actions"; -// import { Spool } from "../job/ZoweJobNode"; -// import SpoolProvider, { encodeJobFile } from "../SpoolProvider"; +import { downloadPS } from "../dataset/actions"; import * as nls from "vscode-nls"; +import { downloadUnixFile } from "../uss/actions"; +import { IconPathByTheme } from "../generators/icons"; // Set up localization nls.config({ @@ -47,6 +46,10 @@ export const JOB_SUBMIT_DIALOG_OPTS = [ localize("zowe.jobs.confirmSubmission.otherUserJobs", "Other user jobs"), localize("zowe.jobs.confirmSubmission.allJobs", "All jobs"), ]; +export type localFileInfo = { + name: string; + path: string; +}; export function filterTreeByString(value: string, treeItems: vscode.QuickPickItem[]): vscode.QuickPickItem[] { ZoweLogger.trace("shared.utils.filterTreeByString called."); @@ -66,14 +69,11 @@ export function filterTreeByString(value: string, treeItems: vscode.QuickPickIte * @param iconFileName {string} Name of icon file with extension * @returns {object} */ -export function getIconPathInResources(iconFileName: string): { - light: string; - dark: string; -} { - return { - light: path.join(globals.ROOTPATH, "resources", "light", iconFileName), - dark: path.join(globals.ROOTPATH, "resources", "dark", iconFileName), - }; +export function getIconPathInResources(iconFileName: string): IconPathByTheme { + const iconPaths = {} as IconPathByTheme; + iconPaths.light = path.join(globals.ROOTPATH, "resources", "light", iconFileName); + iconPaths.dark = path.join(globals.ROOTPATH, "resources", "dark", iconFileName); + return iconPaths; } /************************************************************************************************************* @@ -397,9 +397,16 @@ export async function compareSavedFileContent( */ export async function compareChosenFileContent(): Promise { const docUriArray: vscode.Uri[] = []; - for (const node of globals.filesToCompare) { - const filepath = await getCompareFilePaths(node); - docUriArray.push(vscode.Uri.file(filepath)); + let compareArray: IZoweTreeNode[]; + if (globals.filesToCompare.length > 2) { + compareArray = globals.filesToCompare.slice(Math.max(globals.filesToCompare.length - 2, 0)); + } else { + compareArray = globals.filesToCompare; + } + console.log(compareArray); + for (const node of compareArray) { + const fileInfo = await getCompareFilePaths(node); + docUriArray.push(vscode.Uri.file(fileInfo.path)); } vscode.commands.executeCommand("vscode.diff", docUriArray[0], docUriArray[1]); compareFileCleanup(); @@ -411,19 +418,18 @@ export function compareFileCleanup(): void { globals.setCompareSelectionFalse(); } -async function getCompareFilePaths(node: IZoweTreeNode): Promise { +async function getCompareFilePaths(node: IZoweTreeNode): Promise { ZoweLogger.info(`Getting files ${String(globals.filesToCompare[0].label)} and ${String(globals.filesToCompare[1].label)} for comparison.`); + let fileInfo: localFileInfo; if (isZoweDatasetTreeNode(node)) { - const { documentFilePath } = await prepareDownloadPS(node); - return documentFilePath; + return downloadPS(node); } if (isZoweUSSTreeNode(node)) { // do something with uss tree node // documentFilePath = getUSSDocumentFilePath(node); // if (!fs.existsSync(documentFilePath)) { - // await downloadUnixFile(node, documentFilePath); + return downloadUnixFile(node, true); // } - return ""; } // do something with job spool tree node @@ -434,5 +440,5 @@ async function getCompareFilePaths(node: IZoweTreeNode): Promise { // // Fetch any changes to the spool file if it exists in the SpoolProvider // await spoolFile.fetchContent(); // } - return ""; + return fileInfo; } diff --git a/packages/zowe-explorer/src/uss/ZoweUSSNode.ts b/packages/zowe-explorer/src/uss/ZoweUSSNode.ts index 27a82c72a3..1fa211eb59 100644 --- a/packages/zowe-explorer/src/uss/ZoweUSSNode.ts +++ b/packages/zowe-explorer/src/uss/ZoweUSSNode.ts @@ -19,12 +19,12 @@ import { Profiles } from "../Profiles"; import { ZoweExplorerApiRegister } from "../ZoweExplorerApiRegister"; import { errorHandling, syncSessionNode } from "../utils/ProfilesUtils"; import { getIconByNode } from "../generators/icons/index"; -import { fileExistsCaseSensitveSync } from "../uss/utils"; import * as contextually from "../shared/context"; import { closeOpenedTextFile } from "../utils/workspace"; import * as nls from "vscode-nls"; import { UssFileTree, UssFileType, UssFileUtils } from "./FileStructure"; import { ZoweLogger } from "../utils/LoggerUtils"; +import { downloadUnixFile } from "./actions"; // Set up localization nls.config({ @@ -498,64 +498,64 @@ export class ZoweUSSNode extends ZoweTreeNode implements IZoweUSSTreeNode { */ public async openUSS(download: boolean, previewFile: boolean, ussFileProvider?: IZoweTree): Promise { ZoweLogger.trace("ZoweUSSNode.openUSS called."); - await ussFileProvider.checkCurrentProfile(this); - const doubleClicked = Gui.utils.wasDoubleClicked(this, ussFileProvider); const shouldPreview = doubleClicked ? false : previewFile; + await ussFileProvider.checkCurrentProfile(this); if (Profiles.getInstance().validProfile !== ValidProfileEnum.INVALID) { try { - switch (true) { - // For opening favorited and non-favorited files - case this.getParent().contextValue === globals.FAV_PROFILE_CONTEXT: - break; - case contextually.isUssSession(this.getParent()): - break; - // Handle file path for files in directories and favorited directories - case contextually.isUssDirectory(this.getParent()): - break; - default: - Gui.errorMessage(localize("openUSS.error.invalidNode", "open() called from invalid node.")); - throw Error(localize("openUSS.error.invalidNode", "open() called from invalid node.")); - } - - const documentFilePath = this.getUSSDocumentFilePath(); - // check if some other file is already created with the same name avoid opening file warn user - const fileExists = fs.existsSync(documentFilePath); - if (fileExists && !fileExistsCaseSensitveSync(documentFilePath)) { - Gui.showMessage( - localize( - "openUSS.name.exists", - // eslint-disable-next-line max-len - "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names" - ) - ); - } else { - // if local copy exists, open that instead of pulling from mainframe - if (download || !fileExists) { - const cachedProfile = Profiles.getInstance().loadNamedProfile(this.getProfileName()); - const fullPath = this.fullPath; - const chooseBinary = - this.binary || (await ZoweExplorerApiRegister.getUssApi(cachedProfile).isFileTagBinOrAscii(this.fullPath)); - - const statusMsg = Gui.setStatusBarMessage(localize("ussFile.opening", "$(sync~spin) Opening USS file...")); - const response = await ZoweExplorerApiRegister.getUssApi(cachedProfile).getContents(fullPath, { - file: documentFilePath, - binary: chooseBinary, - returnEtag: true, - encoding: cachedProfile.profile?.encoding, - responseTimeout: cachedProfile.profile?.responseTimeout, - }); - statusMsg.dispose(); - this.downloaded = true; - this.setEtag(response.apiResponse.etag); - } - - // Add document name to recently-opened files - ussFileProvider.addFileHistory(`[${this.getProfile().name}]: ${this.fullPath}`); - ussFileProvider.getTreeView().reveal(this, { select: true, focus: true, expand: false }); + const fileInfo = await downloadUnixFile(this, download); + // switch (true) { + // // For opening favorited and non-favorited files + // case this.getParent().contextValue === globals.FAV_PROFILE_CONTEXT: + // break; + // case contextually.isUssSession(this.getParent()): + // break; + // // Handle file path for files in directories and favorited directories + // case contextually.isUssDirectory(this.getParent()): + // break; + // default: + // Gui.errorMessage(localize("openUSS.error.invalidNode", "open() called from invalid node.")); + // throw Error(localize("openUSS.error.invalidNode", "open() called from invalid node.")); + // } + + // const documentFilePath = this.getUSSDocumentFilePath(); + // // check if some other file is already created with the same name avoid opening file warn user + // const fileExists = fs.existsSync(documentFilePath); + // if (fileExists && !fileExistsCaseSensitveSync(documentFilePath)) { + // Gui.showMessage( + // localize( + // "openUSS.name.exists", + // // eslint-disable-next-line max-len + // "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names" + // ) + // ); + // } else { + // // if local copy exists, open that instead of pulling from mainframe + // if (download || !fileExists) { + // const cachedProfile = Profiles.getInstance().loadNamedProfile(this.getProfileName()); + // const fullPath = this.fullPath; + // const chooseBinary = + // this.binary || (await ZoweExplorerApiRegister.getUssApi(cachedProfile).isFileTagBinOrAscii(this.fullPath)); + + // const statusMsg = Gui.setStatusBarMessage(localize("ussFile.opening", "$(sync~spin) Opening USS file...")); + // const response = await ZoweExplorerApiRegister.getUssApi(cachedProfile).getContents(fullPath, { + // file: documentFilePath, + // binary: chooseBinary, + // returnEtag: true, + // encoding: cachedProfile.profile?.encoding, + // responseTimeout: cachedProfile.profile?.responseTimeout, + // }); + // statusMsg.dispose(); + + // this.setEtag(response.apiResponse.etag); + // } + this.downloaded = true; + // Add document name to recently-opened files + ussFileProvider.addFileHistory(`[${this.getProfile().name}]: ${fileInfo.path}`); + ussFileProvider.getTreeView().reveal(this, { select: true, focus: true, expand: false }); - await this.initializeFileOpening(documentFilePath, shouldPreview); - } + await this.initializeFileOpening(fileInfo.path, shouldPreview); + // } } catch (err) { await errorHandling(err, this.mProfileName); throw err; diff --git a/packages/zowe-explorer/src/uss/actions.ts b/packages/zowe-explorer/src/uss/actions.ts index 43d79c2532..3fca742cb3 100644 --- a/packages/zowe-explorer/src/uss/actions.ts +++ b/packages/zowe-explorer/src/uss/actions.ts @@ -14,7 +14,7 @@ import { imperative, IZosFilesResponse } from "@zowe/cli"; import * as fs from "fs"; import * as globals from "../globals"; import * as path from "path"; -import { concatChildNodes, uploadContent, getSelectedNodeList, getDefaultUri, compareSavedFileContent } from "../shared/utils"; +import { concatChildNodes, uploadContent, getSelectedNodeList, getDefaultUri, compareSavedFileContent, localFileInfo } from "../shared/utils"; import { errorHandling } from "../utils/ProfilesUtils"; import { Gui, ValidProfileEnum, IZoweTree, IZoweUSSTreeNode } from "@zowe/zowe-explorer-api"; import { Profiles } from "../Profiles"; @@ -130,6 +130,56 @@ export async function createUSSNodeDialog(node: IZoweUSSTreeNode, ussFileProvide } } +export async function downloadUnixFile(node: IZoweUSSTreeNode, download: boolean): Promise { + const fileInfo = {} as localFileInfo; + const errorMsg = localize("downloadUnixFile.invalidNode.error", "open() called from invalid node."); + switch (true) { + // For opening favorited and non-favorited files + case node.getParent().contextValue === globals.FAV_PROFILE_CONTEXT: + break; + case contextually.isUssSession(node.getParent()): + break; + // Handle file path for files in directories and favorited directories + case contextually.isUssDirectory(node.getParent()): + break; + default: + Gui.errorMessage(errorMsg); + throw Error(errorMsg); + } + + fileInfo.path = node.getUSSDocumentFilePath(); + // check if some other file is already created with the same name avoid opening file warn user + const fileExists = fs.existsSync(fileInfo.path); + if (fileExists && !fileExistsCaseSensitveSync(fileInfo.path)) { + Gui.showMessage( + localize( + "downloadUnixFile.name.exists", + // eslint-disable-next-line max-len + "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names" + ) + ); + return; + } + // if local copy exists, open that instead of pulling from mainframe + if (download || !fileExists) { + const cachedProfile = Profiles.getInstance().loadNamedProfile(node.getProfileName()); + const fullPath = node.fullPath; + const chooseBinary = node.binary || (await ZoweExplorerApiRegister.getUssApi(cachedProfile).isFileTagBinOrAscii(fullPath)); + + const statusMsg = Gui.setStatusBarMessage(localize("downloadUnixFile.downloading", "$(sync~spin) Downloading USS file...")); + const response = await ZoweExplorerApiRegister.getUssApi(cachedProfile).getContents(fullPath, { + file: fileInfo.path, + binary: chooseBinary, + returnEtag: true, + encoding: cachedProfile.profile?.encoding, + responseTimeout: cachedProfile.profile?.responseTimeout, + }); + statusMsg.dispose(); + node.setEtag(response.apiResponse.etag); + return fileInfo; + } +} + /** * Marks file as deleted from disk *