From 6c1c9b6c7e72aee307c94ee4e83955c7b979b914 Mon Sep 17 00:00:00 2001 From: Trae Yelovich Date: Tue, 24 Oct 2023 14:13:53 -0400 Subject: [PATCH] fix(ftp): adjust getContentsTag calls so only one FTP connection is active Signed-off-by: Trae Yelovich --- .../src/ZoweExplorerFtpMvsApi.ts | 23 +++++++++++-------- .../src/ZoweExplorerFtpUssApi.ts | 18 +++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts index db1be5ff5e..975266ed41 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts @@ -131,6 +131,17 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } const result = this.getDefaultResponse(); const profile = this.checkedProfile(); + + // Save-Save with FTP requires loading the file first + // (moved this block above connection request so only one connection is active at a time) + if (options.returnEtag && options.etag) { + const contentsTag = await this.getContentsTag(dataSetName); + if (contentsTag && contentsTag !== options.etag) { + result.success = false; + result.commandResponse = "Rest API failure with HTTP(S) status 412 Save conflict."; + return result; + } + } let connection; try { connection = await this.ftpClient(profile); @@ -138,15 +149,6 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { ZoweLogger.logImperativeMessage(result.commandResponse, MessageSeverity.ERROR); throw new Error(result.commandResponse); } - // Save-Save with FTP requires loading the file first - if (options.returnEtag && options.etag) { - const contentsTag = await this.getContentsTag(dataSetName); - if (contentsTag && contentsTag !== options.etag) { - result.success = false; - result.commandResponse = "Rest API failure with HTTP(S) status 412 Save conflict."; - return result; - } - } const lrecl: number = dsAtrribute.apiResponse.items[0].lrecl; const data = fs.readFileSync(inputFilePath, { encoding: "utf8" }); const transferOptions: Record = { @@ -178,6 +180,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { await DataSetUtils.uploadDataSet(connection, targetDataset, transferOptions); result.success = true; if (options.returnEtag) { + // release this connection instance because a new one will be made with getContentsTag + this.releaseConnection(connection); + connection = null; const contentsTag = await this.getContentsTag(dataSetName); result.apiResponse = [ { diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts index 128596ee62..baf4509c0c 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts @@ -126,23 +126,27 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { localFile: inputFilePath, }; const result = this.getDefaultResponse(); + // Save-Save with FTP requires loading the file first + // (moved this block above connection request so only one connection is active at a time) + if (returnEtag && etag) { + const contentsTag = await this.getContentsTag(ussFilePath); + if (contentsTag && contentsTag !== etag) { + throw new Error("Rest API failure with HTTP(S) status 412 Save conflict."); + } + } let connection; try { connection = await this.ftpClient(this.checkedProfile()); if (!connection) { throw new Error(result.commandResponse); } - // Save-Save with FTP requires loading the file first - if (returnEtag && etag) { - const contentsTag = await this.getContentsTag(ussFilePath); - if (contentsTag && contentsTag !== etag) { - throw new Error("Rest API failure with HTTP(S) status 412 Save conflict."); - } - } await UssUtils.uploadFile(connection, ussFilePath, transferOptions); result.success = true; if (returnEtag) { + // release this connection instance because a new one will be made with getContentsTag + this.releaseConnection(connection); + connection = null; const contentsTag = await this.getContentsTag(ussFilePath); result.apiResponse.etag = contentsTag; }