|
| 1 | +Prevent state collisions |
| 2 | + |
| 3 | +Previously if you opened different workspaces that had the same filesystem path |
| 4 | +(for example if you have /home/coder on two different machines that are both |
| 5 | +accessed through the same host) they would conflict with each other. This |
| 6 | +ensures that different browser paths will be unique (for example /workspace1 and |
| 7 | +/workspace2). |
| 8 | + |
| 9 | +The easiest way to test is to open files in the same workspace using both / and |
| 10 | +/vscode and make sure they are not interacting with each other. |
| 11 | + |
| 12 | +Index: code-server/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts |
| 13 | +=================================================================== |
| 14 | +--- code-server.orig/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts |
| 15 | ++++ code-server/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts |
| 16 | +@@ -17,6 +17,7 @@ import { AbstractStorageService, isProfi |
| 17 | + import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile'; |
| 18 | + import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace'; |
| 19 | + import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; |
| 20 | ++import { hash } from 'vs/base/common/hash'; |
| 21 | + |
| 22 | + export class BrowserStorageService extends AbstractStorageService { |
| 23 | + |
| 24 | +@@ -67,7 +68,11 @@ export class BrowserStorageService exten |
| 25 | + return `global-${this.profileStorageProfile.id}`; |
| 26 | + } |
| 27 | + case StorageScope.WORKSPACE: |
| 28 | +- return this.payload.id; |
| 29 | ++ // Add a unique ID based on the current path for per-workspace databases. |
| 30 | ++ // This prevents workspaces on different machines that share the same domain |
| 31 | ++ // and file path from colliding (since it does not appear IndexedDB can be |
| 32 | ++ // scoped to a path) as long as they are hosted on different paths. |
| 33 | ++ return this.payload.id + '-' + hash(location.pathname.toString().replace(/\/$/, "")).toString(16); |
| 34 | + } |
| 35 | + } |
| 36 | + |
0 commit comments