@@ -13,7 +13,7 @@ import { URI as Uri, URI } from 'vs/base/common/uri';
1313import { EnvironmentService } from 'vs/platform/environment/node/environmentService' ;
1414import { parseArgs } from 'vs/platform/environment/node/argv' ;
1515import { BackupMainService } from 'vs/platform/backup/electron-main/backupMainService' ;
16- import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup' ;
16+ import { IBackupWorkspacesFormat , ISerializedWorkspace } from 'vs/platform/backup/common/backup' ;
1717import { HotExitConfiguration } from 'vs/platform/files/common/files' ;
1818import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService' ;
1919import { ConsoleLogMainService } from 'vs/platform/log/common/log' ;
@@ -64,6 +64,13 @@ suite('BackupMainService', () => {
6464 } ;
6565 }
6666
67+ function toSerializedWorkspace ( ws : IWorkspaceIdentifier ) : ISerializedWorkspace {
68+ return {
69+ id : ws . id ,
70+ configURIPath : ws . configPath . toString ( )
71+ } ;
72+ }
73+
6774 async function ensureFolderExists ( uri : Uri ) : Promise < void > {
6875 if ( ! fs . existsSync ( uri . fsPath ) ) {
6976 fs . mkdirSync ( uri . fsPath ) ;
@@ -251,12 +258,8 @@ suite('BackupMainService', () => {
251258 suite ( 'migrate folderPath to folderURI' , ( ) => {
252259
253260 test ( 'migration makes sure to preserve existing backups' , async ( ) => {
254- if ( platform . isLinux ) {
255- return ; // TODO:Martin #54483 fix tests
256- }
257-
258- let path1 = path . join ( parentDir , 'folder1' ) . toLowerCase ( ) ;
259- let path2 = path . join ( parentDir , 'folder2' ) . toUpperCase ( ) ;
261+ let path1 = path . join ( parentDir , 'folder1' ) ;
262+ let path2 = path . join ( parentDir , 'FOLDER2' ) ;
260263 let uri1 = Uri . file ( path1 ) ;
261264 let uri2 = Uri . file ( path2 ) ;
262265
@@ -387,10 +390,32 @@ suite('BackupMainService', () => {
387390 assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
388391 } ) ;
389392
393+ test ( 'getWorkspaceBackups() should return [] when rootURIWorkspaces in workspaces.json is not a object array' , async ( ) => {
394+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":{}}' ) ;
395+ await service . initialize ( ) ;
396+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
397+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":{"foo": ["bar"]}}' ) ;
398+ await service . initialize ( ) ;
399+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
400+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":{"foo": []}}' ) ;
401+ await service . initialize ( ) ;
402+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
403+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":{"foo": "bar"}}' ) ;
404+ await service . initialize ( ) ;
405+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
406+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":"foo"}' ) ;
407+ await service . initialize ( ) ;
408+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
409+ fs . writeFileSync ( backupWorkspacesPath , '{"rootURIWorkspaces":1}' ) ;
410+ await service . initialize ( ) ;
411+ assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
412+ } ) ;
413+
390414 test ( 'getWorkspaceBackups() should return [] when files.hotExit = "onExitAndWindowClose"' , async ( ) => {
391- service . registerWorkspaceBackupSync ( toWorkspace ( fooFile . fsPath . toUpperCase ( ) ) ) ;
415+ const upperFooPath = fooFile . fsPath . toUpperCase ( ) ;
416+ service . registerWorkspaceBackupSync ( toWorkspace ( upperFooPath ) ) ;
392417 assert . equal ( service . getWorkspaceBackups ( ) . length , 1 ) ;
393- assert . deepEqual ( service . getWorkspaceBackups ( ) . map ( r => r . configPath ) , [ fooFile . fsPath . toUpperCase ( ) ] ) ;
418+ assertEqualUris ( service . getWorkspaceBackups ( ) . map ( r => r . configPath ) , [ URI . file ( upperFooPath ) ] ) ;
394419 configService . setUserConfiguration ( 'files.hotExit' , HotExitConfiguration . ON_EXIT_AND_WINDOW_CLOSE ) ;
395420 await service . initialize ( ) ;
396421 assert . deepEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
@@ -447,7 +472,7 @@ suite('BackupMainService', () => {
447472 await ensureFolderExists ( existingTestFolder1 ) ;
448473
449474 const workspacesJson : IBackupWorkspacesFormat = {
450- rootWorkspaces : [ ] ,
475+ rootURIWorkspaces : [ ] ,
451476 folderURIWorkspaces : [ existingTestFolder1 . toString ( ) , existingTestFolder1 . toString ( ) ] ,
452477 emptyWorkspaceInfos : [ ]
453478 } ;
@@ -464,7 +489,7 @@ suite('BackupMainService', () => {
464489 await ensureFolderExists ( existingTestFolder1 ) ;
465490
466491 const workspacesJson : IBackupWorkspacesFormat = {
467- rootWorkspaces : [ ] ,
492+ rootURIWorkspaces : [ ] ,
468493 folderURIWorkspaces : [ existingTestFolder1 . toString ( ) , existingTestFolder1 . toString ( ) . toLowerCase ( ) ] ,
469494 emptyWorkspaceInfos : [ ]
470495 } ;
@@ -487,7 +512,7 @@ suite('BackupMainService', () => {
487512 const workspace3 = await ensureWorkspaceExists ( toWorkspace ( workspacePath . toLowerCase ( ) ) ) ;
488513
489514 const workspacesJson : IBackupWorkspacesFormat = {
490- rootWorkspaces : [ workspace1 , workspace2 , workspace3 ] ,
515+ rootURIWorkspaces : [ workspace1 , workspace2 , workspace3 ] . map ( toSerializedWorkspace ) ,
491516 folderURIWorkspaces : [ ] ,
492517 emptyWorkspaceInfos : [ ]
493518 } ;
@@ -496,11 +521,11 @@ suite('BackupMainService', () => {
496521
497522 const buffer = await pfs . readFile ( backupWorkspacesPath , 'utf-8' ) ;
498523 const json = < IBackupWorkspacesFormat > JSON . parse ( buffer ) ;
499- assert . equal ( json . rootWorkspaces . length , platform . isLinux ? 3 : 1 ) ;
524+ assert . equal ( json . rootURIWorkspaces . length , platform . isLinux ? 3 : 1 ) ;
500525 if ( platform . isLinux ) {
501- assert . deepEqual ( json . rootWorkspaces . map ( r => r . configPath ) , [ workspacePath , workspacePath . toUpperCase ( ) , workspacePath . toLowerCase ( ) ] ) ;
526+ assert . deepEqual ( json . rootURIWorkspaces . map ( r => r . configURIPath ) , [ URI . file ( workspacePath ) , URI . file ( workspacePath . toUpperCase ( ) ) , URI . file ( workspacePath . toLowerCase ( ) ) ] ) ;
502527 } else {
503- assert . deepEqual ( json . rootWorkspaces . map ( r => r . configPath ) , [ workspacePath ] , 'should return the first duplicated entry' ) ;
528+ assert . deepEqual ( json . rootURIWorkspaces . map ( r => r . configURIPath ) , [ URI . file ( workspacePath ) ] , 'should return the first duplicated entry' ) ;
504529 }
505530 } ) ;
506531 } ) ;
@@ -521,16 +546,16 @@ suite('BackupMainService', () => {
521546 const ws2 = toWorkspace ( barFile . fsPath ) ;
522547 service . registerWorkspaceBackupSync ( ws2 ) ;
523548
524- assert . deepEqual ( service . getWorkspaceBackups ( ) . map ( b => b . configPath ) , [ fooFile . fsPath , barFile . fsPath ] ) ;
549+ assertEqualUris ( service . getWorkspaceBackups ( ) . map ( b => b . configPath ) , [ fooFile , barFile ] ) ;
525550 assert . equal ( ws1 . id , service . getWorkspaceBackups ( ) [ 0 ] . id ) ;
526551 assert . equal ( ws2 . id , service . getWorkspaceBackups ( ) [ 1 ] . id ) ;
527552
528553 const buffer = await pfs . readFile ( backupWorkspacesPath , 'utf-8' ) ;
529554 const json = < IBackupWorkspacesFormat > JSON . parse ( buffer ) ;
530555
531- assert . deepEqual ( json . rootWorkspaces . map ( b => b . configPath ) , [ fooFile . fsPath , barFile . fsPath ] ) ;
532- assert . equal ( ws1 . id , json . rootWorkspaces [ 0 ] . id ) ;
533- assert . equal ( ws2 . id , json . rootWorkspaces [ 1 ] . id ) ;
556+ assert . deepEqual ( json . rootURIWorkspaces . map ( b => b . configURIPath ) , [ fooFile . toString ( ) , barFile . toString ( ) ] ) ;
557+ assert . equal ( ws1 . id , json . rootURIWorkspaces [ 0 ] . id ) ;
558+ assert . equal ( ws2 . id , json . rootURIWorkspaces [ 1 ] . id ) ;
534559 } ) ;
535560 } ) ;
536561
@@ -544,11 +569,12 @@ suite('BackupMainService', () => {
544569 } ) ;
545570
546571 test ( 'should always store the workspace path in workspaces.json using the case given, regardless of whether the file system is case-sensitive (root workspace)' , ( ) => {
547- service . registerWorkspaceBackupSync ( toWorkspace ( fooFile . fsPath . toUpperCase ( ) ) ) ;
548- assert . deepEqual ( service . getWorkspaceBackups ( ) . map ( b => b . configPath ) , [ fooFile . fsPath . toUpperCase ( ) ] ) ;
572+ const upperFooPath = fooFile . fsPath . toUpperCase ( ) ;
573+ service . registerWorkspaceBackupSync ( toWorkspace ( upperFooPath ) ) ;
574+ assertEqualUris ( service . getWorkspaceBackups ( ) . map ( b => b . configPath ) , [ URI . file ( upperFooPath ) ] ) ;
549575 return pfs . readFile ( backupWorkspacesPath , 'utf-8' ) . then ( buffer => {
550576 const json = < IBackupWorkspacesFormat > JSON . parse ( buffer ) ;
551- assert . deepEqual ( json . rootWorkspaces . map ( b => b . configPath ) , [ fooFile . fsPath . toUpperCase ( ) ] ) ;
577+ assert . deepEqual ( json . rootURIWorkspaces . map ( b => b . configURIPath ) , [ URI . file ( upperFooPath ) . toString ( ) ] ) ;
552578 } ) ;
553579 } ) ;
554580
@@ -576,11 +602,11 @@ suite('BackupMainService', () => {
576602 service . unregisterWorkspaceBackupSync ( ws1 ) ;
577603 return pfs . readFile ( backupWorkspacesPath , 'utf-8' ) . then ( buffer => {
578604 const json = < IBackupWorkspacesFormat > JSON . parse ( buffer ) ;
579- assert . deepEqual ( json . rootWorkspaces . map ( r => r . configPath ) , [ barFile . fsPath ] ) ;
605+ assert . deepEqual ( json . rootURIWorkspaces . map ( r => r . configURIPath ) , [ barFile . toString ( ) ] ) ;
580606 service . unregisterWorkspaceBackupSync ( ws2 ) ;
581607 return pfs . readFile ( backupWorkspacesPath , 'utf-8' ) . then ( content => {
582608 const json2 = < IBackupWorkspacesFormat > JSON . parse ( content ) ;
583- assert . deepEqual ( json2 . rootWorkspaces , [ ] ) ;
609+ assert . deepEqual ( json2 . rootURIWorkspaces , [ ] ) ;
584610 } ) ;
585611 } ) ;
586612 } ) ;
@@ -604,7 +630,7 @@ suite('BackupMainService', () => {
604630
605631 await ensureFolderExists ( existingTestFolder1 ) ; // make sure backup folder exists, so the folder is not removed on loadSync
606632
607- const workspacesJson : IBackupWorkspacesFormat = { rootWorkspaces : [ ] , folderURIWorkspaces : [ existingTestFolder1 . toString ( ) ] , emptyWorkspaceInfos : [ ] } ;
633+ const workspacesJson : IBackupWorkspacesFormat = { rootURIWorkspaces : [ ] , folderURIWorkspaces : [ existingTestFolder1 . toString ( ) ] , emptyWorkspaceInfos : [ ] } ;
608634 await pfs . writeFile ( backupWorkspacesPath , JSON . stringify ( workspacesJson ) ) ;
609635 await service . initialize ( ) ;
610636 service . unregisterFolderBackupSync ( barFile ) ;
0 commit comments