mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 * disable strict null check
This commit is contained in:
@@ -11,14 +11,16 @@ import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { IStateService } from 'vs/platform/state/common/state';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
type StorageDatebase = { [key: string]: any; };
|
||||
|
||||
export class FileStorage {
|
||||
|
||||
private _database: object | null = null;
|
||||
private _database: StorageDatebase | null = null;
|
||||
private lastFlushedSerializedDatabase: string | null = null;
|
||||
|
||||
constructor(private dbPath: string, private onError: (error: Error) => void) { }
|
||||
|
||||
private get database(): object {
|
||||
private get database(): StorageDatebase {
|
||||
if (!this._database) {
|
||||
this._database = this.loadSync();
|
||||
}
|
||||
@@ -27,27 +29,36 @@ export class FileStorage {
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
try {
|
||||
const contents = await readFile(this.dbPath);
|
||||
if (this._database) {
|
||||
return; // return if database was already loaded
|
||||
}
|
||||
|
||||
try {
|
||||
this.lastFlushedSerializedDatabase = contents.toString();
|
||||
this._database = JSON.parse(this.lastFlushedSerializedDatabase);
|
||||
} catch (error) {
|
||||
this._database = {};
|
||||
}
|
||||
const database = await this.loadAsync();
|
||||
|
||||
if (this._database) {
|
||||
return; // return if database was already loaded
|
||||
}
|
||||
|
||||
this._database = database;
|
||||
}
|
||||
|
||||
private loadSync(): StorageDatebase {
|
||||
try {
|
||||
this.lastFlushedSerializedDatabase = fs.readFileSync(this.dbPath).toString();
|
||||
|
||||
return JSON.parse(this.lastFlushedSerializedDatabase);
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
this.onError(error);
|
||||
}
|
||||
|
||||
this._database = {};
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
private loadSync(): object {
|
||||
private async loadAsync(): Promise<StorageDatebase> {
|
||||
try {
|
||||
this.lastFlushedSerializedDatabase = fs.readFileSync(this.dbPath).toString();
|
||||
this.lastFlushedSerializedDatabase = (await readFile(this.dbPath)).toString();
|
||||
|
||||
return JSON.parse(this.lastFlushedSerializedDatabase);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user