mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
This reverts commit d15a3fcc98.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import * as fs from 'fs';
|
||||
import { dirname } from 'vs/base/common/path';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import * as json from 'vs/base/common/json';
|
||||
import { statLink } from 'vs/base/node/pfs';
|
||||
@@ -41,17 +41,20 @@ export interface IConfigOptions<T> {
|
||||
* - delayed processing of changes to accomodate for lots of changes
|
||||
* - configurable defaults
|
||||
*/
|
||||
export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
|
||||
export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
|
||||
private cache: T;
|
||||
private parseErrors: json.ParseError[];
|
||||
private disposed: boolean;
|
||||
private loaded: boolean;
|
||||
private timeoutHandle: NodeJS.Timer | null;
|
||||
private disposables: IDisposable[];
|
||||
private readonly _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>;
|
||||
|
||||
constructor(private _path: string, private options: IConfigOptions<T> = { defaultConfig: Object.create(null), onError: error => console.error(error) }) {
|
||||
super();
|
||||
this._onDidUpdateConfiguration = this._register(new Emitter<IConfigurationChangeEvent<T>>());
|
||||
this.disposables = [];
|
||||
|
||||
this._onDidUpdateConfiguration = new Emitter<IConfigurationChangeEvent<T>>();
|
||||
this.disposables.push(this._onDidUpdateConfiguration);
|
||||
|
||||
this.registerWatcher();
|
||||
this.initAsync();
|
||||
@@ -108,10 +111,10 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
|
||||
try {
|
||||
this.parseErrors = [];
|
||||
res = this.options.parse ? this.options.parse(raw, this.parseErrors) : json.parse(raw, this.parseErrors);
|
||||
|
||||
return res || this.options.defaultConfig;
|
||||
} catch (error) {
|
||||
return this.options.defaultConfig; // Ignore parsing errors
|
||||
// Ignore parsing errors
|
||||
return this.options.defaultConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +125,7 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
|
||||
this.watch(parentFolder, true);
|
||||
|
||||
// Check if the path is a symlink and watch its target if so
|
||||
this.handleSymbolicLink().then(undefined, () => { /* ignore error */ });
|
||||
this.handleSymbolicLink().then(undefined, error => { /* ignore error */ });
|
||||
}
|
||||
|
||||
private async handleSymbolicLink(): Promise<void> {
|
||||
@@ -140,9 +143,9 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
|
||||
}
|
||||
|
||||
if (isFolder) {
|
||||
this._register(watchFolder(path, (type, path) => path === this._path ? this.onConfigFileChange() : undefined, error => this.options.onError(error)));
|
||||
this.disposables.push(watchFolder(path, (type, path) => path === this._path ? this.onConfigFileChange() : undefined, error => this.options.onError(error)));
|
||||
} else {
|
||||
this._register(watchFile(path, () => this.onConfigFileChange(), error => this.options.onError(error)));
|
||||
this.disposables.push(watchFile(path, (type, path) => this.onConfigFileChange(), error => this.options.onError(error)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +187,6 @@ export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
|
||||
|
||||
dispose(): void {
|
||||
this.disposed = true;
|
||||
super.dispose();
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ export function readFile(path: string, encoding?: string): Promise<Buffer | stri
|
||||
// According to node.js docs (https://nodejs.org/docs/v6.5.0/api/fs.html#fs_fs_writefile_file_data_options_callback)
|
||||
// it is not safe to call writeFile() on the same path multiple times without waiting for the callback to return.
|
||||
// Therefor we use a Queue on the path that is given to us to sequentialize calls to the same path properly.
|
||||
const writeFilePathQueues: Map<string, Queue<void>> = new Map();
|
||||
const writeFilePathQueue: { [path: string]: Queue<void> } = Object.create(null);
|
||||
|
||||
export function writeFile(path: string, data: string, options?: IWriteFileOptions): Promise<void>;
|
||||
export function writeFile(path: string, data: Buffer, options?: IWriteFileOptions): Promise<void>;
|
||||
@@ -249,20 +249,18 @@ function toQueueKey(path: string): string {
|
||||
}
|
||||
|
||||
function ensureWriteFileQueue(queueKey: string): Queue<void> {
|
||||
const existingWriteFileQueue = writeFilePathQueues.get(queueKey);
|
||||
if (existingWriteFileQueue) {
|
||||
return existingWriteFileQueue;
|
||||
let writeFileQueue = writeFilePathQueue[queueKey];
|
||||
if (!writeFileQueue) {
|
||||
writeFileQueue = new Queue<void>();
|
||||
writeFilePathQueue[queueKey] = writeFileQueue;
|
||||
|
||||
const onFinish = Event.once(writeFileQueue.onFinished);
|
||||
onFinish(() => {
|
||||
delete writeFilePathQueue[queueKey];
|
||||
writeFileQueue.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
const writeFileQueue = new Queue<void>();
|
||||
writeFilePathQueues.set(queueKey, writeFileQueue);
|
||||
|
||||
const onFinish = Event.once(writeFileQueue.onFinished);
|
||||
onFinish(() => {
|
||||
writeFilePathQueues.delete(queueKey);
|
||||
writeFileQueue.dispose();
|
||||
});
|
||||
|
||||
return writeFileQueue;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as fs from 'fs';
|
||||
import { promisify } from 'util';
|
||||
import * as cp from 'child_process';
|
||||
import * as nls from 'vs/nls';
|
||||
import * as Types from 'vs/base/common/types';
|
||||
@@ -405,7 +404,7 @@ export function createQueuedSender(childProcess: cp.ChildProcess): IQueuedSender
|
||||
}
|
||||
|
||||
export namespace win32 {
|
||||
export async function findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string> {
|
||||
export function findExecutable(command: string, cwd?: string, paths?: string[]): string {
|
||||
// If we have an absolute path then we take it.
|
||||
if (path.isAbsolute(command)) {
|
||||
return command;
|
||||
@@ -436,15 +435,15 @@ export namespace win32 {
|
||||
} else {
|
||||
fullPath = path.join(cwd, pathEntry, command);
|
||||
}
|
||||
if (await promisify(fs.exists)(fullPath)) {
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
let withExtension = fullPath + '.com';
|
||||
if (await promisify(fs.exists)(withExtension)) {
|
||||
if (fs.existsSync(withExtension)) {
|
||||
return withExtension;
|
||||
}
|
||||
withExtension = fullPath + '.exe';
|
||||
if (await promisify(fs.exists)(withExtension)) {
|
||||
if (fs.existsSync(withExtension)) {
|
||||
return withExtension;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user