Implement a no sync rule (#7216)

* implement a no sync rule

* fix linting disable

* fix unused imports

* exclude more testing

* clean up fs usage

* clean up more fs usage

* remove duplicate of code

* fix compile errors
This commit is contained in:
Anthony Dresser
2019-09-17 13:32:42 -07:00
committed by GitHub
parent 4d62983680
commit 28d453fced
31 changed files with 305 additions and 201 deletions

View File

@@ -5,7 +5,7 @@
import * as vscode from 'vscode';
import * as azdata from 'azdata';
import * as fs from 'fs';
import { promises as fs } from 'fs';
import * as fspath from 'path';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@@ -22,7 +22,7 @@ import { AppContext } from '../appContext';
import { TreeNode } from './treeNodes';
import { MssqlObjectExplorerNodeProvider } from './objectExplorerNodeProvider';
function getSaveableUri(apiWrapper: ApiWrapper, fileName: string, isPreview?: boolean): vscode.Uri {
async function getSaveableUri(apiWrapper: ApiWrapper, fileName: string, isPreview?: boolean): Promise<vscode.Uri> {
let root = utils.getUserHome();
let workspaceFolders = apiWrapper.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
@@ -33,7 +33,7 @@ function getSaveableUri(apiWrapper: ApiWrapper, fileName: string, isPreview?: bo
let fileNum = 1;
let fileNameWithoutExtension = fspath.parse(fileName).name;
let fileExtension = fspath.parse(fileName).ext;
while (fs.existsSync(fspath.join(root, fileName))) {
while (await utils.exists(fspath.join(root, fileName))) {
fileName = `${fileNameWithoutExtension}-${fileNum}${fileExtension}`;
fileNum++;
}
@@ -82,7 +82,7 @@ export class UploadFilesCommand extends ProgressCommand {
};
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
if (fileUris) {
let files: IFile[] = fileUris.map(uri => uri.fsPath).map(this.mapPathsToFiles());
let files: IFile[] = await Promise.all(fileUris.map(uri => uri.fsPath).map(this.mapPathsToFiles()));
await this.executeWithProgress(
(cancelToken: vscode.CancellationTokenSource) => this.writeFiles(files, folderNode, cancelToken),
localize('uploading', 'Uploading files to HDFS'), true,
@@ -99,9 +99,9 @@ export class UploadFilesCommand extends ProgressCommand {
}
}
private mapPathsToFiles(): (value: string, index: number, array: string[]) => File {
return (path: string) => {
let isDir = fs.lstatSync(path).isDirectory();
private mapPathsToFiles(): (value: string, index: number, array: string[]) => Promise<File> {
return async (path: string) => {
let isDir = (await fs.lstat(path)).isDirectory();
return new File(path, isDir);
};
}
@@ -115,9 +115,9 @@ export class UploadFilesCommand extends ProgressCommand {
if (file.isDirectory) {
let dirName = fspath.basename(file.path);
let subFolder = await folderNode.mkdir(dirName);
let children: IFile[] = fs.readdirSync(file.path)
let children: IFile[] = await Promise.all((await fs.readdir(file.path))
.map(childFileName => joinHdfsPath(file.path, childFileName))
.map(this.mapPathsToFiles());
.map(this.mapPathsToFiles()));
this.writeFiles(children, subFolder, cancelToken);
} else {
await folderNode.writeFile(file);
@@ -258,7 +258,7 @@ export class SaveFileCommand extends ProgressCommand {
try {
let fileNode = await getNode<FileNode>(context, this.appContext);
if (fileNode) {
let defaultUri = getSaveableUri(this.apiWrapper, fspath.basename(fileNode.hdfsPath));
let defaultUri = await getSaveableUri(this.apiWrapper, fspath.basename(fileNode.hdfsPath));
let fileUri: vscode.Uri = await this.apiWrapper.showSaveDialog({
defaultUri: defaultUri
});
@@ -330,7 +330,7 @@ export class PreviewFileCommand extends ProgressCommand {
private async showNotebookDocument(fileName: string, connectionProfile?: azdata.IConnectionProfile,
initialContent?: string
): Promise<azdata.nb.NotebookEditor> {
let docUri: vscode.Uri = getSaveableUri(this.apiWrapper, fileName, true)
let docUri: vscode.Uri = (await getSaveableUri(this.apiWrapper, fileName, true))
.with({ scheme: constants.UNTITLED_SCHEMA });
return await azdata.nb.showNotebookDocument(docUri, {
connectionProfile: connectionProfile,
@@ -340,7 +340,7 @@ export class PreviewFileCommand extends ProgressCommand {
}
private async openTextDocument(fileName: string): Promise<vscode.TextDocument> {
let docUri: vscode.Uri = getSaveableUri(this.apiWrapper, fileName, true);
let docUri: vscode.Uri = await getSaveableUri(this.apiWrapper, fileName, true);
if (docUri) {
docUri = docUri.with({ scheme: constants.UNTITLED_SCHEMA });
return await this.apiWrapper.openTextDocument(docUri);