diff --git a/CHANGELOG.md b/CHANGELOG.md index b097dd7f..9fbb9caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the z/OS FTP Plug-in for Zowe CLI will be documented in t ## Recent Changes +- BugFix: Upload dataset using Buffer, stead of string. [2533](https://github.com/zowe/vscode-extension-for-zowe/issues/2533) - Simplify the preparation for JCL system tests diff --git a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts index 032ec87d..c682e1f6 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts @@ -13,7 +13,7 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToDataSetHandler from "../../../../../src/cli/upload/stdin-to-data-set/StdinToDataSet.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload file to data set handler", () => { +describe("Upload stdin to data set handler", () => { it("should return no data set if the data set is not found.", async () => { const handler = new UploadStdinToDataSetHandler(); @@ -37,4 +37,31 @@ describe("Upload file to data set handler", () => { expect(mockResponse.console.log.mock.calls[0][2]).toBe("DS1"); }); + it("should upload contents with Buffer.", async () => { + // This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533 + // FTP client checks whether the string to put is a local file path first. + // If yes, it puts the whole file; otherwise, it puts the string as the contents. + // On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//". + + const handler = new UploadStdinToDataSetHandler(); + + CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss"))); + CoreUtils.addCarriageReturns = jest.fn().mockReturnValue(("sss")); + const mockResponse = TestUtils.getMockResponse(); + const mockUploadDataset = jest.fn(); + const mockParams: any = { + arguments: { + dataSet: "ds1" + }, + connection: { + uploadDataset: mockUploadDataset + }, + response: mockResponse + }; + await handler.processFTP(mockParams); + // The contents to upload must be Buffer. FTP client tries to fs.stat() first, + // if the contents is string. + expect(mockUploadDataset.mock.calls[0][0] instanceof Buffer).toBeTruthy(); + }); + }); diff --git a/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts index bb39b238..f45fd362 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts @@ -13,9 +13,9 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToUssFileHandler from "../../../../../src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload file to data set handler", () => { +describe("Upload stdin to USS file handler", () => { - it("should return no data set if the data set is not found.", async () => { + it("should return no data set if the USS file is not found.", async () => { const handler = new UploadStdinToUssFileHandler(); CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss"))); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f05bc369..0fe02762 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "license": "EPL-2.0", "dependencies": { "zos-node-accessor": "1.0.16" diff --git a/package.json b/package.json index c0db9fec..623dc347 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "author": "Zowe", "repository": { "type": "git", diff --git a/src/api/DataSetUtils.ts b/src/api/DataSetUtils.ts index 78bd45e2..26bb017d 100644 --- a/src/api/DataSetUtils.ts +++ b/src/api/DataSetUtils.ts @@ -142,7 +142,7 @@ export class DataSetUtils { this.log.debug("Attempting to upload to data set '%s' in transfer mode '%s'", dsn, option.transferType); } if (transferType === TRANSFER_TYPE_ASCII) { - content = CoreUtils.addCarriageReturns(content.toString()); + content = Buffer.from(CoreUtils.addCarriageReturns(content.toString())); } await connection.uploadDataset(content, "'" + dsn + "'", transferType, siteparm); }