mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode 2b0b9136329c181a9e381463a1f7dc3a2d105a34 (#4880)
This commit is contained in:
@@ -12,6 +12,6 @@ export interface IStateService {
|
||||
|
||||
getItem<T>(key: string, defaultValue: T): T;
|
||||
getItem<T>(key: string, defaultValue?: T): T | undefined;
|
||||
setItem(key: string, data: any): void;
|
||||
setItem(key: string, data?: object | string | number | boolean | undefined | null): void;
|
||||
removeItem(key: string): void;
|
||||
}
|
||||
@@ -6,11 +6,10 @@
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as fs from 'fs';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
|
||||
import { writeFileSync, readFile } from 'vs/base/node/pfs';
|
||||
import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { IStateService } from 'vs/platform/state/common/state';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { readFile } from 'vs/base/node/pfs';
|
||||
|
||||
export class FileStorage {
|
||||
|
||||
@@ -69,7 +68,7 @@ export class FileStorage {
|
||||
return res;
|
||||
}
|
||||
|
||||
setItem(key: string, data: any): void {
|
||||
setItem(key: string, data?: object | string | number | boolean | undefined | null): void {
|
||||
|
||||
// Remove an item when it is undefined or null
|
||||
if (isUndefinedOrNull(data)) {
|
||||
@@ -103,7 +102,7 @@ export class FileStorage {
|
||||
}
|
||||
|
||||
try {
|
||||
writeFileAndFlushSync(this.dbPath, serializedDatabase); // permission issue can happen here
|
||||
writeFileSync(this.dbPath, serializedDatabase); // permission issue can happen here
|
||||
this.lastFlushedSerializedDatabase = serializedDatabase;
|
||||
} catch (error) {
|
||||
this.onError(error);
|
||||
@@ -136,7 +135,7 @@ export class StateService implements IStateService {
|
||||
return this.fileStorage.getItem(key, defaultValue);
|
||||
}
|
||||
|
||||
setItem(key: string, data: any): void {
|
||||
setItem(key: string, data?: object | string | number | boolean | undefined | null): void {
|
||||
this.fileStorage.setItem(key, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,21 +6,21 @@
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as extfs from 'vs/base/node/extfs';
|
||||
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
|
||||
import { FileStorage } from 'vs/platform/state/node/stateService';
|
||||
import { mkdirp, rimraf, RimRafMode, writeFileSync } from 'vs/base/node/pfs';
|
||||
|
||||
suite('StateService', () => {
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'stateservice');
|
||||
const storageFile = path.join(parentDir, 'storage.json');
|
||||
|
||||
teardown(done => {
|
||||
extfs.del(parentDir, os.tmpdir(), done);
|
||||
rimraf(parentDir, RimRafMode.MOVE).then(done, done);
|
||||
});
|
||||
|
||||
test('Basics', () => {
|
||||
return extfs.mkdirp(parentDir).then(() => {
|
||||
extfs.writeFileAndFlushSync(storageFile, '');
|
||||
return mkdirp(parentDir).then(() => {
|
||||
writeFileSync(storageFile, '');
|
||||
|
||||
let service = new FileStorage(storageFile, () => null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user