Skip to content

Commit 6337ee4

Browse files
authored
Make unique database per location (#46)
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.
1 parent 96e2413 commit 6337ee4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/vs/platform/storage/browser/storageService.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { InMemoryStorageDatabase, isStorageItemsChangeEvent, IStorage, IStorageD
1313
import { ILogService } from 'vs/platform/log/common/log';
1414
import { AbstractStorageService, IS_NEW_KEY, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
1515
import { IWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
16+
import { hash } from 'vs/base/common/hash';
1617

1718
export class BrowserStorageService extends AbstractStorageService {
1819

@@ -214,7 +215,15 @@ export class IndexedDBStorageDatabase extends Disposable implements IIndexedDBSt
214215
) {
215216
super();
216217

217-
this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${options.id}`;
218+
/**
219+
* Add a unique ID based on the current path. This prevents workspaces on
220+
* different machines that share the same domain and file path from
221+
* colliding (since it does not appear IndexedDB can be scoped to a path) as
222+
* long as they are hosted on different paths.
223+
* @author coder
224+
*/
225+
const windowId = hash(location.pathname.toString()).toString(16);
226+
this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${windowId}-${options.id}`;
218227
this.broadcastChannel = options.broadcastChanges && ('BroadcastChannel' in window) ? new BroadcastChannel(IndexedDBStorageDatabase.STORAGE_BROADCAST_CHANNEL) : undefined;
219228

220229
this.whenConnected = this.connect();

0 commit comments

Comments
 (0)