mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
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:
@@ -28,6 +28,7 @@ import { registerBooksWidget } from './dashboard/bookWidget';
|
||||
import { createMssqlApi } from './mssqlApiFactory';
|
||||
import { localize } from './localize';
|
||||
import { SqlToolsServer } from './sqlToolsServer';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', 'This sample code loads the file into a data frame and shows the first 10 results.');
|
||||
|
||||
@@ -42,8 +43,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
|
||||
}
|
||||
|
||||
// ensure our log path exists
|
||||
if (!(await Utils.pfs.exists(context.logPath))) {
|
||||
await Utils.pfs.mkdir(context.logPath);
|
||||
if (!(await Utils.exists(context.logPath))) {
|
||||
await fs.mkdir(context.logPath);
|
||||
}
|
||||
|
||||
let prompter: IPrompter = new CodeAdapter();
|
||||
@@ -200,7 +201,7 @@ async function handleOpenNotebookTask(profile: azdata.IConnectionProfile): Promi
|
||||
async function handleOpenClusterStatusNotebookTask(profile: azdata.IConnectionProfile, appContext: AppContext): Promise<void> {
|
||||
const notebookRelativePath: string = 'notebooks/tsg/cluster-status.ipynb';
|
||||
const notebookFullPath: string = path.join(appContext.extensionContext.extensionPath, notebookRelativePath);
|
||||
if (!Utils.fileExists(notebookFullPath)) {
|
||||
if (!(await Utils.exists(notebookFullPath))) {
|
||||
vscode.window.showErrorMessage(localize("fileNotFound", "Unable to find the file specified"));
|
||||
} else {
|
||||
const title: string = Utils.findNextUntitledEditorName(notebookFullPath);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as fspath from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as vscode from 'vscode';
|
||||
import * as utils from '../../../utils';
|
||||
import * as LocalizedConstants from '../../../localizedConstants';
|
||||
@@ -223,7 +222,7 @@ export class SparkConfigurationTab {
|
||||
|
||||
// 1. For local file Source check whether they existed.
|
||||
if (this._dataModel.isMainSourceFromLocal) {
|
||||
if (!fs.existsSync(this._dataModel.localFileSourcePath)) {
|
||||
if (!(await utils.exists(this._dataModel.localFileSourcePath))) {
|
||||
this._dataModel.showDialogError(LocalizedConstants.sparkJobSubmissionLocalFileNotExisted(this._dataModel.localFileSourcePath));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
import * as fs from 'fs';
|
||||
import * as fspath from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
@@ -143,7 +142,7 @@ export class SparkJobSubmissionModel {
|
||||
return Promise.reject(localize('sparkJobSubmission_localFileOrFolderNotSpecified.', 'Property localFilePath or hdfsFolderPath is not specified. '));
|
||||
}
|
||||
|
||||
if (!fs.existsSync(localFilePath)) {
|
||||
if (!(await utils.exists(localFilePath))) {
|
||||
return Promise.reject(LocalizedConstants.sparkJobSubmissionLocalFileNotExisted(localFilePath));
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ export function getTemplatePath(extensionPath: string, templateName: string): st
|
||||
}
|
||||
export function shellWhichResolving(cmd: string): Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
which(cmd, (err, foundPath) => {
|
||||
which(cmd, async (err, foundPath) => {
|
||||
if (err) {
|
||||
resolve(undefined);
|
||||
} else {
|
||||
// NOTE: Using realpath b/c some system installs are symlinked from */bin
|
||||
resolve(fs.realpathSync(foundPath));
|
||||
resolve(await fs.promises.realpath(foundPath));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,8 +20,7 @@ import { AppContext } from './appContext';
|
||||
import { DacFxService } from './dacfx/dacFxService';
|
||||
import { CmsService } from './cms/cmsService';
|
||||
import { CompletionExtensionParams, CompletionExtLoadRequest } from './contracts';
|
||||
import { promisify } from 'util';
|
||||
import { readFile } from 'fs';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const outputChannel = vscode.window.createOutputChannel(Constants.serviceName);
|
||||
const statusView = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||
@@ -70,7 +69,7 @@ export class SqlToolsServer {
|
||||
}
|
||||
|
||||
private async download(context: AppContext): Promise<string> {
|
||||
const rawConfig = await promisify(readFile)(path.join(context.extensionContext.extensionPath, 'config.json'));
|
||||
const rawConfig = await fs.readFile(path.join(context.extensionContext.extensionPath, 'config.json'));
|
||||
this.config = JSON.parse(rawConfig.toString());
|
||||
this.config.installDirectory = path.join(__dirname, this.config.installDirectory);
|
||||
this.config.proxy = vscode.workspace.getConfiguration('http').get('proxy');
|
||||
|
||||
@@ -10,8 +10,7 @@ import * as crypto from 'crypto';
|
||||
import * as os from 'os';
|
||||
import * as findRemoveSync from 'find-remove';
|
||||
import * as constants from './constants';
|
||||
import * as fs from 'fs';
|
||||
import { promisify } from 'util';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const configTracingLevel = 'tracingLevel';
|
||||
const configLogRetentionMinutes = 'logRetentionMinutes';
|
||||
@@ -31,17 +30,6 @@ export function getAppDataPath() {
|
||||
}
|
||||
}
|
||||
|
||||
export namespace pfs {
|
||||
|
||||
export function exists(path: string): Promise<boolean> {
|
||||
return promisify(fs.exists)(path);
|
||||
}
|
||||
|
||||
export function mkdir(path: string, mode?: number): Promise<void> {
|
||||
return promisify(fs.mkdir)(path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a file name that is not already used in the target directory
|
||||
* @param filePath source notebook file name
|
||||
@@ -61,14 +49,6 @@ export function findNextUntitledEditorName(filePath: string): string {
|
||||
return title;
|
||||
}
|
||||
|
||||
export function fileExists(file: string): boolean {
|
||||
return fs.existsSync(file);
|
||||
}
|
||||
|
||||
export function copyFile(source: string, target: string): void {
|
||||
fs.copyFileSync(source, target);
|
||||
}
|
||||
|
||||
export function removeOldLogFiles(logPath: string, prefix: string): JSON {
|
||||
return findRemoveSync(logPath, { age: { seconds: getConfigLogRetentionSeconds() }, limit: getConfigLogFilesRemovalLimit() });
|
||||
}
|
||||
@@ -303,3 +283,12 @@ export function logDebug(msg: any): void {
|
||||
console.log(outputMsg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function exists(path: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user