Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/patches/unique-db.diff
Florian Ritterhoff 2bfe15b3e9
chore: update Code to 1.70 (#5422)
* Update upstream Code to 1.70

* Update CSP hashes

* Update comment on remote authority

Also remove it from script-src since it is invalid anyway.

* Use absolute path for disable download patch

Just to keep it consistent with the other imports.  We initially added
the patch like this so it was not part of the upgrade but might as well
fix it now.

* Fix inability to change language while code-server is running

Co-authored-by: Asher <ash@coder.com>
2022-08-16 20:27:23 -05:00

68 lines
2.7 KiB
Diff

Prevent state collisions
Previously if you opened different workspaces that had the same filesystem path
(for example if you have /home/coder on two different machines that are both
accessed through the same host) they would conflict with each other. This
ensures that different browser paths will be unique (for example /workspace1 and
/workspace2).
The easiest way to test is to open files in the same workspace using both / and
/vscode and make sure they are not interacting with each other.
It should also migrate old databases which can be tested by opening in an old
code-server.
This has e2e tests.
Index: code-server/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts
===================================================================
--- code-server.orig/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts
+++ code-server/lib/vscode/src/vs/workbench/services/storage/browser/storageService.ts
@@ -17,6 +17,7 @@ import { AbstractStorageService, isProfi
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IAnyWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
+import { hash } from 'vs/base/common/hash';
export class BrowserStorageService extends AbstractStorageService {
@@ -67,7 +68,11 @@ export class BrowserStorageService exten
return `global-${this.profileStorageProfile.id}`;
}
case StorageScope.WORKSPACE:
- return this.payload.id;
+ // Add a unique ID based on the current path for per-workspace databases.
+ // This prevents workspaces on different machines that share the same domain
+ // and file path from colliding (since it does not appear IndexedDB can be
+ // scoped to a path) as long as they are hosted on different paths.
+ return this.payload.id + '-' + hash(location.pathname.toString().replace(/\/$/, "")).toString(16);
}
}
@@ -141,6 +146,25 @@ export class BrowserStorageService exten
await this.workspaceStorage.init();
+ const firstWorkspaceOpen = this.workspaceStorage.getBoolean(IS_NEW_KEY);
+ if (firstWorkspaceOpen === undefined) {
+ // Migrate the old database.
+ let db: IIndexedDBStorageDatabase | undefined
+ try {
+ db = await IndexedDBStorageDatabase.create({ id: this.payload.id }, this.logService)
+ const items = await db.getItems()
+ for (const [key, value] of items) {
+ this.workspaceStorage.set(key, value);
+ }
+ } catch (error) {
+ this.logService.error(`[IndexedDB Storage ${this.payload.id}] migrate error: ${toErrorMessage(error)}`);
+ } finally {
+ if (db) {
+ db.close()
+ }
+ }
+ }
+
this.updateIsNew(this.workspaceStorage);
}