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

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as fs from 'fs';
import { promises as fs } from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as constants from './constants';
@@ -54,12 +54,12 @@ function pushDisposable(disposable: vscode.Disposable): void {
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
extensionContext = context;
const apiWrapper = new ApiWrapper();
let appContext = new AppContext(extensionContext, apiWrapper);
let storagePath = findOrMakeStoragePath();
let storagePath = await findOrMakeStoragePath();
if (!storagePath) {
return undefined;
}
@@ -82,12 +82,21 @@ export function activate(context: vscode.ExtensionContext) {
};
}
async function exists(path: string): Promise<boolean> {
try {
await fs.access(path);
return true;
} catch (e) {
return false;
}
}
// Create the folder for storing the token caches
function findOrMakeStoragePath() {
async function findOrMakeStoragePath() {
let storagePath = path.join(getDefaultLogLocation(), constants.extensionName);
try {
if (!fs.existsSync(storagePath)) {
fs.mkdirSync(storagePath);
if (!(await exists(storagePath))) {
await fs.mkdir(storagePath);
console.log('Initialized Azure account extension storage.');
}
}
@@ -124,4 +133,3 @@ function registerCommands(appContext: AppContext, azureResourceTree: AzureResour
registerAzureResourceDatabaseCommands(appContext);
}