@@ -21,7 +21,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
2121import { VSBuffer } from 'vs/base/common/buffer' ;
2222import { TextSnapshotReadable } from 'vs/workbench/services/textfile/common/textfiles' ;
2323import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation' ;
24- import { isNative } from 'vs/base/common/platform' ;
2524
2625export interface IBackupFilesModel {
2726 resolve ( backupRoot : URI ) : Promise < IBackupFilesModel > ;
@@ -118,12 +117,17 @@ export class BackupFileService implements IBackupFileService {
118117 ) {
119118 const backupWorkspacePath = environmentService . configuration . backupPath ;
120119 if ( backupWorkspacePath ) {
121- this . impl = new BackupFileServiceImpl ( backupWorkspacePath , fileService ) ;
120+ this . impl = new BackupFileServiceImpl ( backupWorkspacePath , this . hashPath , fileService ) ;
122121 } else {
123- this . impl = new InMemoryBackupFileService ( ) ;
122+ this . impl = new InMemoryBackupFileService ( this . hashPath ) ;
124123 }
125124 }
126125
126+ protected hashPath ( resource : URI ) : string {
127+ const str = resource . scheme === Schemas . file || resource . scheme === Schemas . untitled ? resource . fsPath : resource . toString ( ) ;
128+ return hash ( str ) . toString ( 16 ) ;
129+ }
130+
127131 initialize ( backupWorkspacePath : string ) : void {
128132 if ( this . impl instanceof BackupFileServiceImpl ) {
129133 this . impl . initialize ( backupWorkspacePath ) ;
@@ -179,6 +183,7 @@ class BackupFileServiceImpl implements IBackupFileService {
179183
180184 constructor (
181185 backupWorkspacePath : string ,
186+ private readonly hashPath : ( resource : URI ) => string ,
182187 @IFileService private readonly fileService : IFileService
183188 ) {
184189 this . isShuttingDown = false ;
@@ -357,7 +362,7 @@ class BackupFileServiceImpl implements IBackupFileService {
357362 }
358363
359364 toBackupResource ( resource : URI ) : URI {
360- return joinPath ( this . backupWorkspacePath , resource . scheme , hashPath ( resource ) ) ;
365+ return joinPath ( this . backupWorkspacePath , resource . scheme , this . hashPath ( resource ) ) ;
361366 }
362367}
363368
@@ -367,6 +372,8 @@ export class InMemoryBackupFileService implements IBackupFileService {
367372
368373 private backups : Map < string , ITextSnapshot > = new Map ( ) ;
369374
375+ constructor ( private readonly hashPath : ( resource : URI ) => string ) { }
376+
370377 hasBackups ( ) : Promise < boolean > {
371378 return Promise . resolve ( this . backups . size > 0 ) ;
372379 }
@@ -413,21 +420,8 @@ export class InMemoryBackupFileService implements IBackupFileService {
413420 }
414421
415422 toBackupResource ( resource : URI ) : URI {
416- return URI . file ( join ( resource . scheme , hashPath ( resource ) ) ) ;
423+ return URI . file ( join ( resource . scheme , this . hashPath ( resource ) ) ) ;
417424 }
418425}
419426
420- /*
421- * Exported only for testing
422- */
423- export function hashPath ( resource : URI ) : string {
424- const str = resource . scheme === Schemas . file || resource . scheme === Schemas . untitled ? resource . fsPath : resource . toString ( ) ;
425- if ( isNative ) {
426- const _crypto : typeof crypto = require . __$__nodeRequire ( 'crypto' ) ;
427- return _crypto [ 'createHash' ] ( 'md5' ) . update ( str ) . digest ( 'hex' ) ;
428- }
429-
430- return hash ( str ) . toString ( 16 ) ;
431- }
432-
433427registerSingleton ( IBackupFileService , BackupFileService ) ;
0 commit comments