Skip to content

Commit

Permalink
Merge pull request #2378 from zowe/buffertoussfile-file-tagging
Browse files Browse the repository at this point in the history
add tagging for upload.bufferToUssFile
  • Loading branch information
awharn authored Dec 10, 2024
2 parents 803fbd6 + f2aac76 commit cb09152
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,19 +755,22 @@ 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));
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> => 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];
Expand All @@ -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 });
});
Expand Down
9 changes: 7 additions & 2 deletions packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -890,7 +897,6 @@ export class Upload {
*/
private static get log(): Logger {
return Logger.getAppLogger();
// return Logger.getConsoleLogger();
}


Expand All @@ -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({
Expand Down

0 comments on commit cb09152

Please sign in to comment.