diff --git a/packages/zosfiles/CHANGELOG.md b/packages/zosfiles/CHANGELOG.md index c113aa555..e9715b05a 100644 --- a/packages/zosfiles/CHANGELOG.md +++ b/packages/zosfiles/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Zowe z/OS files SDK package will be documented in this file. +## Recent Changes + +- BugFix: Corrected the `Upload.BufferToUssFile()` SDK function to properly tag uploaded files. [#2378](https://github.com/zowe/zowe-cli/pull/2378) + ## `8.9.0` - Enhancement: Added a `List.membersMatchingPattern` method to download all members that match a specific pattern.[#2359](https://github.com/zowe/zowe-cli/pull/2359) diff --git a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts index de22e9569..158729d6c 100644 --- a/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/upload/Upload.system.test.ts @@ -755,11 +755,14 @@ describe("Upload USS file", () => { let error; let uploadResponse; let getResponse; + let tagResponse; + const data: Buffer = Buffer.from(testdata); try { uploadResponse = await Upload.bufferToUssFile(REAL_SESSION, ussname, data, { binary: true }); getResponse = await Get.USSFile(REAL_SESSION, ussname, {binary: true}); + tagResponse = await Utilities.isFileTagBinOrAscii(REAL_SESSION, ussname); } catch (err) { error = err; Imperative.console.info("Error: " + inspect(error)); @@ -767,7 +770,7 @@ describe("Upload USS file", () => { expect(error).toBeFalsy(); expect(getResponse).toEqual(Buffer.from(data.toString())); - + expect(tagResponse).toBe(true); }); it("should upload a USS file from local file", async () => { let error; diff --git a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts index 7e7e8bf36..28812678c 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/upload/Upload.unit.test.ts @@ -1661,6 +1661,9 @@ describe("z/OS Files - Upload", () => { expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data }); }); it("should return with proper response when upload USS file in binary", async () => { + const chtagSpy = jest.spyOn(Utilities, "chtag"); + chtagSpy.mockImplementation(async (): Promise => null); + const data: Buffer = Buffer.from("testing"); const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, dsName); const headers = [ZosmfHeaders.OCTET_STREAM, ZosmfHeaders.X_IBM_BINARY, ZosmfHeaders.ACCEPT_ENCODING]; @@ -1673,7 +1676,7 @@ describe("z/OS Files - Upload", () => { expect(error).toBeUndefined(); expect(USSresponse).toBeDefined(); - + expect(chtagSpy).toHaveBeenCalled(); expect(zosmfExpectSpy).toHaveBeenCalledTimes(1); expect(zosmfExpectSpy).toHaveBeenCalledWith(dummySession, { reqHeaders: headers, resource: endpoint, writeData: data }); }); diff --git a/packages/zosfiles/src/methods/upload/Upload.ts b/packages/zosfiles/src/methods/upload/Upload.ts index 528150b96..2f984eded 100644 --- a/packages/zosfiles/src/methods/upload/Upload.ts +++ b/packages/zosfiles/src/methods/upload/Upload.ts @@ -457,6 +457,7 @@ export class Upload { ImperativeExpect.toNotBeEqual(options.record, true, ZosFilesMessages.unsupportedDataType.message); options.binary = options.binary ? options.binary : false; ImperativeExpect.toNotBeNullOrUndefined(ussname, ZosFilesMessages.missingUSSFileName.message); + const origUssname = ussname; ussname = ZosFilesUtils.sanitizeUssPathForRestCall(ussname); const endpoint = ZosFilesConstants.RESOURCE + ZosFilesConstants.RES_USS_FILES + "/" + ussname; @@ -487,6 +488,12 @@ export class Upload { apiResponse.etag = uploadRequest.response.headers.etag; } + if (options.encoding != null) { + await Utilities.chtag(session, origUssname, Tag.TEXT, options.encoding); + } else if (options.binary) { + await Utilities.chtag(session, origUssname, Tag.BINARY); + } + return { success: true, commandResponse: ZosFilesMessages.dataSetUploadedSuccessfully.message, @@ -890,7 +897,6 @@ export class Upload { */ private static get log(): Logger { return Logger.getAppLogger(); - // return Logger.getConsoleLogger(); } @@ -915,7 +921,6 @@ export class Upload { const response: IUploadDir[] = []; if (Upload.hasDirs(dirPath)) { const directories = fs.readdirSync(dirPath).filter((file) => IO.isDir(path.normalize(path.join(dirPath, file)))); - // directories = directories.filter((file) => IO.isDir(path.normalize(path.join(dirPath, file)))); for (let index = 0; index < directories.length; index++) { const dirFullPath = path.normalize(path.join(dirPath, directories[index])); response.push({