Skip to content

Commit

Permalink
fix(ftp): adjust getContentsTag calls so only one FTP connection is a…
Browse files Browse the repository at this point in the history
…ctive

Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Oct 24, 2023
1 parent 610a812 commit 6c1c9b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
23 changes: 14 additions & 9 deletions packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,24 @@ 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);
if (!connection) {
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<string, any> = {
Expand Down Expand Up @@ -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 = [
{
Expand Down
18 changes: 11 additions & 7 deletions packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6c1c9b6

Please sign in to comment.