@@ -255,9 +255,9 @@ suite('BackupMainService', () => {
255255 assert . equal ( 1 , fs . readdirSync ( path . join ( backupHome , emptyBackups [ 0 ] . backupFolder ) ) . length ) ;
256256 } ) ;
257257
258- suite ( 'migrate folderPath to folderURI ' , ( ) => {
258+ suite ( 'migrate path to URI ' , ( ) => {
259259
260- test ( 'migration makes sure to preserve existing backups' , async ( ) => {
260+ test ( 'migration folder path to URI makes sure to preserve existing backups' , async ( ) => {
261261 let path1 = path . join ( parentDir , 'folder1' ) ;
262262 let path2 = path . join ( parentDir , 'FOLDER2' ) ;
263263 let uri1 = Uri . file ( path1 ) ;
@@ -293,8 +293,38 @@ suite('BackupMainService', () => {
293293 const newBackupFolder2 = service . toBackupPath ( uri2 ) ;
294294 assert . ok ( fs . existsSync ( path . join ( newBackupFolder2 , Schemas . file , 'unsaved2.txt' ) ) ) ;
295295 } ) ;
296+
297+ test ( 'migrate storage file' , async ( ) => {
298+ let folderPath = path . join ( parentDir , 'f1' ) ;
299+ const backupFolderPath = service . toLegacyBackupPath ( folderPath ) ;
300+ if ( ! fs . existsSync ( backupFolderPath ) ) {
301+ fs . mkdirSync ( backupFolderPath ) ;
302+ fs . mkdirSync ( path . join ( backupFolderPath , Schemas . file ) ) ;
303+ await pfs . writeFile ( path . join ( backupFolderPath , Schemas . file , 'unsaved1.txt' ) , 'Legacy' ) ;
304+ }
305+
306+ let workspacePath = path . join ( parentDir , 'f2.code-workspace' ) ;
307+ const workspace = toWorkspace ( workspacePath ) ;
308+
309+ const backupWorkspacePath = service . toBackupPath ( workspace . id ) ;
310+ if ( ! fs . existsSync ( backupWorkspacePath ) ) {
311+ fs . mkdirSync ( backupWorkspacePath ) ;
312+ fs . mkdirSync ( path . join ( backupWorkspacePath , Schemas . file ) ) ;
313+ await pfs . writeFile ( path . join ( backupWorkspacePath , Schemas . file , 'unsaved2.txt' ) , 'Legacy' ) ;
314+ }
315+
316+
317+ const workspacesJson = { rootWorkspaces : [ { id : workspace . id , configPath : workspacePath } ] , folderWorkspaces : [ folderPath ] , emptyWorkspaces : [ ] } ;
318+ await pfs . writeFile ( backupWorkspacesPath , JSON . stringify ( workspacesJson ) ) ;
319+ await service . initialize ( ) ;
320+ const content = await pfs . readFile ( backupWorkspacesPath , 'utf-8' ) ;
321+ const json = ( < IBackupWorkspacesFormat > JSON . parse ( content ) ) ;
322+ assert . deepEqual ( json . folderURIWorkspaces , [ URI . file ( folderPath ) . toString ( ) ] ) ;
323+ assert . deepEqual ( json . rootURIWorkspaces , [ { id : workspace . id , configPath : URI . file ( workspacePath ) . toString ( ) } ] ) ;
324+ } ) ;
296325 } ) ;
297326
327+
298328 suite ( 'loadSync' , ( ) => {
299329 test ( 'getFolderBackupPaths() should return [] when workspaces.json doesn\'t exist' , ( ) => {
300330 assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
0 commit comments