@@ -15,6 +15,7 @@ import { copy, exists, mkdirp, writeFile } from 'vs/base/node/pfs';
1515import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
1616import { IWorkspaceInitializationPayload , isWorkspaceIdentifier , isSingleFolderWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces' ;
1717import { onUnexpectedError } from 'vs/base/common/errors' ;
18+ import { assertIsDefined , assertAllDefined } from 'vs/base/common/types' ;
1819
1920export class NativeStorageService extends Disposable implements IStorageService {
2021
@@ -31,11 +32,11 @@ export class NativeStorageService extends Disposable implements IStorageService
3132
3233 private globalStorage : IStorage ;
3334
34- private workspaceStoragePath : string ;
35- private workspaceStorage : IStorage ;
36- private workspaceStorageListener : IDisposable ;
35+ private workspaceStoragePath : string | undefined ;
36+ private workspaceStorage : IStorage | undefined ;
37+ private workspaceStorageListener : IDisposable | undefined ;
3738
38- private initializePromise : Promise < void > ;
39+ private initializePromise : Promise < void > | undefined ;
3940
4041 constructor (
4142 globalStorageDatabase : IStorageDatabase ,
@@ -191,22 +192,24 @@ export class NativeStorageService extends Disposable implements IStorageService
191192
192193 // Do it
193194 await Promise . all ( [
194- this . globalStorage . close ( ) ,
195- this . workspaceStorage . close ( )
195+ this . getStorage ( StorageScope . GLOBAL ) . close ( ) ,
196+ this . getStorage ( StorageScope . WORKSPACE ) . close ( )
196197 ] ) ;
197198 }
198199
199200 private getStorage ( scope : StorageScope ) : IStorage {
200- return scope === StorageScope . GLOBAL ? this . globalStorage : this . workspaceStorage ;
201+ return assertIsDefined ( scope === StorageScope . GLOBAL ? this . globalStorage : this . workspaceStorage ) ;
201202 }
202203
203204 async logStorage ( ) : Promise < void > {
205+ const [ workspaceStorage , workspaceStoragePath ] = assertAllDefined ( this . workspaceStorage , this . workspaceStoragePath ) ;
206+
204207 const result = await Promise . all ( [
205208 this . globalStorage . items ,
206- this . workspaceStorage . items
209+ workspaceStorage . items
207210 ] ) ;
208211
209- logStorage ( result [ 0 ] , result [ 1 ] , this . environmentService . globalStorageHome , this . workspaceStoragePath ) ;
212+ logStorage ( result [ 0 ] , result [ 1 ] , this . environmentService . globalStorageHome , workspaceStoragePath ) ;
210213 }
211214
212215 async migrate ( toWorkspace : IWorkspaceInitializationPayload ) : Promise < void > {
@@ -215,15 +218,15 @@ export class NativeStorageService extends Disposable implements IStorageService
215218 }
216219
217220 // Close workspace DB to be able to copy
218- await this . workspaceStorage . close ( ) ;
221+ await this . getStorage ( StorageScope . WORKSPACE ) . close ( ) ;
219222
220223 // Prepare new workspace storage folder
221224 const result = await this . prepareWorkspaceStorageFolder ( toWorkspace ) ;
222225
223226 const newWorkspaceStoragePath = join ( result . path , NativeStorageService . WORKSPACE_STORAGE_NAME ) ;
224227
225228 // Copy current storage over to new workspace storage
226- await copy ( this . workspaceStoragePath , newWorkspaceStoragePath ) ;
229+ await copy ( assertIsDefined ( this . workspaceStoragePath ) , newWorkspaceStoragePath ) ;
227230
228231 // Recreate and init workspace storage
229232 return this . createWorkspaceStorage ( newWorkspaceStoragePath ) . init ( ) ;
0 commit comments