From df11b4a84667797f6c4044ddaee9429be8904cde Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 17 Feb 2022 23:00:01 +0000 Subject: [PATCH 1/2] Make unique database per location This fixes collisions where VS Code is serving a workspace with the same name but on a different machine and hosted on the same domain. --- src/vs/platform/storage/browser/storageService.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts index 014c9ef4e1ccb..b27d50bc6e97b 100644 --- a/src/vs/platform/storage/browser/storageService.ts +++ b/src/vs/platform/storage/browser/storageService.ts @@ -13,6 +13,7 @@ import { InMemoryStorageDatabase, isStorageItemsChangeEvent, IStorage, IStorageD import { ILogService } from 'vs/platform/log/common/log'; import { AbstractStorageService, IS_NEW_KEY, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces'; +import { hash } from 'vs/base/common/hash'; export class BrowserStorageService extends AbstractStorageService { @@ -214,7 +215,14 @@ export class IndexedDBStorageDatabase extends Disposable implements IIndexedDBSt ) { super(); - this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${options.id}`; + /** + * Add a unique ID based on the current path. 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. + */ + const windowId = hash(location.pathname.toString()).toString(16); + this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${windowId}-${options.id}`; this.broadcastChannel = options.broadcastChanges && ('BroadcastChannel' in window) ? new BroadcastChannel(IndexedDBStorageDatabase.STORAGE_BROADCAST_CHANNEL) : undefined; this.whenConnected = this.connect(); From 5f443eebf5eac90318180f75d897d0fcb6a59c8c Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 18 Feb 2022 18:11:42 +0000 Subject: [PATCH 2/2] Tag comment with author --- src/vs/platform/storage/browser/storageService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts index b27d50bc6e97b..84d388e928719 100644 --- a/src/vs/platform/storage/browser/storageService.ts +++ b/src/vs/platform/storage/browser/storageService.ts @@ -220,6 +220,7 @@ export class IndexedDBStorageDatabase extends Disposable implements IIndexedDBSt * 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. + * @author coder */ const windowId = hash(location.pathname.toString()).toString(16); this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${windowId}-${options.id}`;