Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores committed Nov 7, 2023
1 parent 6852a1d commit e390537
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1501,18 +1501,15 @@ describe("Dataset Actions Unit Tests - Function saveFile", () => {
(testDocument as any).fileName = path.join(globals.DS_DIR, testDocument.fileName);
const logSpy = jest.spyOn(ZoweLogger, "warn");
const commandSpy = jest.spyOn(vscode.commands, "executeCommand");
const applyEditSpy = jest.spyOn(vscode.workspace, "applyEdit");
jest.spyOn(fs, "statSync").mockReturnValueOnce({ size: 0 } as any);

await dsActions.saveFile(testDocument, blockMocks.testDatasetTree);

expect(logSpy).toBeCalledWith("Remote file has changed. Presenting with way to resolve file.");
expect(mocked(sharedUtils.concatChildNodes)).toBeCalled();
expect(commandSpy).toBeCalledWith("workbench.files.action.compareWithSaved");
expect(applyEditSpy).toHaveBeenCalledTimes(2);
logSpy.mockClear();
commandSpy.mockClear();
applyEditSpy.mockClear();
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/i18n/sample/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"ds.selectSortOpt": "Select a sorting option for {0}",
"jobs.selectSortOpt": "Select a sorting option for jobs in {0}",
"ds.filterBy": "Filter PDS members...",
"ds.sortBy": "Sort PDS members..."
"ds.sortBy": "Sort PDS members...",
"selectForCompare": "Select for Compare",
"compareWithSelected": "Compare with Selected",
"compareWithSelectedReadOnly": "Compare with Selected (Read-Only)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"deleteUssPrompt.confirmation.cancel.log.debug": "Delete action was canceled.",
"ZoweUssNode.copyDownload.progress": "Copying file structure...",
"uss.paste.apiNotAvailable": "The paste operation is not supported for this node.",
"ZoweUssNode.copyUpload.progress": "Pasting files..."
"ZoweUssNode.copyUpload.progress": "Pasting files...",
"downloadUnixFile.invalidNode.error": "open() called from invalid node.",
"downloadUnixFile.name.exists": "There is already a file with the same name. Please change your OS file system settings if you want to give case sensitive file names",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"ds.selectSortOpt": "Select a sorting option for {0}",
"jobs.selectSortOpt": "Select a sorting option for jobs in {0}",
"ds.filterBy": "Filter PDS members...",
"ds.sortBy": "Sort PDS members..."
"ds.sortBy": "Sort PDS members...",
"selectForCompare": "Select for Compare",
"compareWithSelected": "Compare with Selected",
"compareWithSelectedReadOnly": "Compare with Selected (Read-Only)",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export let DS_DIR: string;
export let CONFIG_PATH; // set during activate
export let ISTHEIA = false; // set during activate
export let LOG: imperative.Logger;
export const COMMAND_COUNT = 115;
export const COMMAND_COUNT = 119;
export const MAX_SEARCH_HISTORY = 5;
export const MAX_FILE_HISTORY = 10;
export const MS_PER_SEC = 1000;
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Job, Spool } from "./ZoweJobNode";
import * as nls from "vscode-nls";
import SpoolProvider, { encodeJobFile, getSpoolFiles, matchSpool } from "../SpoolProvider";
import { ZoweLogger } from "../utils/LoggerUtils";
import { SORT_DIRS, getDefaultUri } from "../shared/utils";
import { SORT_DIRS } from "../shared/utils";
import { ZosJobsProvider } from "./ZosJobsProvider";
import { JOB_SORT_OPTS } from "./utils";
import * as globals from "../globals";
Expand Down
70 changes: 0 additions & 70 deletions packages/zowe-explorer/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

// Generic utility functions related to all node types. See ./src/utils.ts for other utility functions.

import * as fs from "fs";
import * as vscode from "vscode";
import * as path from "path";
import * as globals from "../globals";
import * as os from "os";
import { Gui, IZoweTreeNode, IZoweNodeType, IZoweDatasetTreeNode, IZoweUSSTreeNode, IZoweJobTreeNode } from "@zowe/zowe-explorer-api";
import { ZoweExplorerApiRegister } from "../ZoweExplorerApiRegister";
import * as nls from "vscode-nls";
Expand Down Expand Up @@ -343,71 +341,3 @@ export function jobStringValidator(text: string, localizedParam: "owner" | "pref
return text.length > globals.JOBS_MAX_PREFIX ? localize("searchJobs.prefix.invalid", "Invalid job prefix") : null;
}
}

export function getDefaultUri(): vscode.Uri {
return vscode.workspace.workspaceFolders?.[0]?.uri ?? vscode.Uri.file(os.homedir());
}

/**
* Function that triggers compare of the old and new document in the active editor
* @param {vscode.TextDocument} doc - document to update and compare with previous content
* @param {IZoweDatasetTreeNode | IZoweUSSTreeNode} node - IZoweTreeNode
* @param {string} label - {optional} used by IZoweDatasetTreeNode to getContents of file
* @param {boolean} binary - {optional} used by IZoweUSSTreeNode to getContents of file
* @param {imperative.IProfileLoaded} profile - {optional}
* @returns {Promise<void>}
*/
export async function compareFileContent(
doc: vscode.TextDocument,
node: IZoweDatasetTreeNode | IZoweUSSTreeNode,
label?: string,
binary?: boolean,
profile?: imperative.IProfileLoaded
): Promise<void> {
await markDocumentUnsaved(doc);
const prof = node ? node.getProfile() : profile;
let downloadResponse;

if (isTypeUssTreeNode(node)) {
downloadResponse = await ZoweExplorerApiRegister.getUssApi(prof).getContents(node.fullPath, {
file: node.getUSSDocumentFilePath(),
binary,
returnEtag: true,
encoding: prof.profile?.encoding,
responseTimeout: prof.profile?.responseTimeout,
});
} else {
downloadResponse = await ZoweExplorerApiRegister.getMvsApi(prof).getContents(label, {
file: doc.fileName,
returnEtag: true,
encoding: prof.profile?.encoding,
responseTimeout: prof.profile?.responseTimeout,
});
}

// If local and remote file size are the same, then VS Code won't detect
// there is a conflict and remote changes may get overwritten. To work
// around this limitation of VS Code, when the sizes are identical we
// temporarily add a trailing newline byte to the local copy which forces
// the file size to be different. This is a terrible hack but it works.
// See https://github.com/microsoft/vscode/issues/119002
const oldSize = doc.getText().length;
const newSize = fs.statSync(doc.fileName).size;
if (newSize === oldSize) {
const edits = new vscode.WorkspaceEdit();
edits.insert(doc.uri, doc.positionAt(oldSize), doc.eol.toString());
await vscode.workspace.applyEdit(edits);
}
ZoweLogger.warn(localize("saveFile.etagMismatch.log.warning", "Remote file has changed. Presenting with way to resolve file."));
await vscode.commands.executeCommand("workbench.files.action.compareWithSaved");
if (newSize === oldSize) {
const edits2 = new vscode.WorkspaceEdit();
edits2.delete(doc.uri, new vscode.Range(doc.positionAt(oldSize), doc.positionAt(oldSize + doc.eol.toString().length)));
await vscode.workspace.applyEdit(edits2);
}
// re-assign etag, so that it can be used with subsequent requests
const downloadEtag = downloadResponse?.apiResponse?.etag;
if (node && downloadEtag !== node.getEtag()) {
node.setEtag(downloadEtag);
}
}

0 comments on commit e390537

Please sign in to comment.