55
66import * as fs from 'fs' ;
77import * as gracefulFs from 'graceful-fs' ;
8- import { createHash } from 'crypto' ;
98import { webFrame } from 'electron' ;
109import { importEntries , mark } from 'vs/base/common/performance' ;
1110import { Workbench } from 'vs/workbench/browser/workbench' ;
1211import { NativeWindow } from 'vs/workbench/electron-browser/window' ;
1312import { setZoomLevel , setZoomFactor , setFullscreen } from 'vs/base/browser/browser' ;
1413import { domContentLoaded , addDisposableListener , EventType , scheduleAtNextAnimationFrame } from 'vs/base/browser/dom' ;
1514import { onUnexpectedError } from 'vs/base/common/errors' ;
16- import { isLinux , isMacintosh , isWindows } from 'vs/base/common/platform' ;
1715import { URI } from 'vs/base/common/uri' ;
1816import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService' ;
1917import { NativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService' ;
2018import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
2119import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
22- import { stat } from 'vs/base/node/pfs' ;
2320import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/nativeKeymapService' ;
2421import { INativeWindowConfiguration } from 'vs/platform/windows/node/window' ;
2522import { ISingleFolderWorkspaceIdentifier , IWorkspaceInitializationPayload , ISingleFolderWorkspaceInitializationPayload , reviveWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces' ;
@@ -51,6 +48,8 @@ import { FileUserDataProvider } from 'vs/workbench/services/userData/common/file
5148import { basename } from 'vs/base/common/resources' ;
5249import { IProductService } from 'vs/platform/product/common/productService' ;
5350import product from 'vs/platform/product/common/product' ;
51+ import { NativeResourceIdentityService } from 'vs/platform/resource/node/resourceIdentityServiceImpl' ;
52+ import { IResourceIdentityService } from 'vs/platform/resource/common/resourceIdentityService' ;
5453
5554class DesktopMain extends Disposable {
5655
@@ -214,7 +213,10 @@ class DesktopMain extends Disposable {
214213 fileService . registerProvider ( Schemas . vscodeRemote , remoteFileSystemProvider ) ;
215214 }
216215
217- const payload = await this . resolveWorkspaceInitializationPayload ( ) ;
216+ const resourceIdentityService = this . _register ( new NativeResourceIdentityService ( ) ) ;
217+ serviceCollection . set ( IResourceIdentityService , resourceIdentityService ) ;
218+
219+ const payload = await this . resolveWorkspaceInitializationPayload ( resourceIdentityService ) ;
218220
219221 const services = await Promise . all ( [
220222 this . createWorkspaceService ( payload , fileService , remoteAgentService , logService ) . then ( service => {
@@ -240,7 +242,7 @@ class DesktopMain extends Disposable {
240242 return { serviceCollection, logService, storageService : services [ 1 ] } ;
241243 }
242244
243- private async resolveWorkspaceInitializationPayload ( ) : Promise < IWorkspaceInitializationPayload > {
245+ private async resolveWorkspaceInitializationPayload ( resourceIdentityService : IResourceIdentityService ) : Promise < IWorkspaceInitializationPayload > {
244246
245247 // Multi-root workspace
246248 if ( this . environmentService . configuration . workspace ) {
@@ -250,7 +252,7 @@ class DesktopMain extends Disposable {
250252 // Single-folder workspace
251253 let workspaceInitializationPayload : IWorkspaceInitializationPayload | undefined ;
252254 if ( this . environmentService . configuration . folderUri ) {
253- workspaceInitializationPayload = await this . resolveSingleFolderWorkspaceInitializationPayload ( this . environmentService . configuration . folderUri ) ;
255+ workspaceInitializationPayload = await this . resolveSingleFolderWorkspaceInitializationPayload ( this . environmentService . configuration . folderUri , resourceIdentityService ) ;
254256 }
255257
256258 // Fallback to empty workspace if we have no payload yet.
@@ -270,46 +272,16 @@ class DesktopMain extends Disposable {
270272 return workspaceInitializationPayload ;
271273 }
272274
273- private async resolveSingleFolderWorkspaceInitializationPayload ( folderUri : ISingleFolderWorkspaceIdentifier ) : Promise < ISingleFolderWorkspaceInitializationPayload | undefined > {
274-
275- // Return early the folder is not local
276- if ( folderUri . scheme !== Schemas . file ) {
277- return { id : createHash ( 'md5' ) . update ( folderUri . toString ( ) ) . digest ( 'hex' ) , folder : folderUri } ;
278- }
279-
280- function computeLocalDiskFolderId ( folder : URI , stat : fs . Stats ) : string {
281- let ctime : number | undefined ;
282- if ( isLinux ) {
283- ctime = stat . ino ; // Linux: birthtime is ctime, so we cannot use it! We use the ino instead!
284- } else if ( isMacintosh ) {
285- ctime = stat . birthtime . getTime ( ) ; // macOS: birthtime is fine to use as is
286- } else if ( isWindows ) {
287- if ( typeof stat . birthtimeMs === 'number' ) {
288- ctime = Math . floor ( stat . birthtimeMs ) ; // Windows: fix precision issue in node.js 8.x to get 7.x results (see https://github.com/nodejs/node/issues/19897)
289- } else {
290- ctime = stat . birthtime . getTime ( ) ;
291- }
292- }
293-
294- // we use the ctime as extra salt to the ID so that we catch the case of a folder getting
295- // deleted and recreated. in that case we do not want to carry over previous state
296- return createHash ( 'md5' ) . update ( folder . fsPath ) . update ( ctime ? String ( ctime ) : '' ) . digest ( 'hex' ) ;
297- }
298-
299- // For local: ensure path is absolute and exists
275+ private async resolveSingleFolderWorkspaceInitializationPayload ( folderUri : ISingleFolderWorkspaceIdentifier , resourceIdentityService : IResourceIdentityService ) : Promise < ISingleFolderWorkspaceInitializationPayload | undefined > {
300276 try {
301- const sanitizedFolderPath = sanitizeFilePath ( folderUri . fsPath , process . env [ 'VSCODE_CWD' ] || process . cwd ( ) ) ;
302- const fileStat = await stat ( sanitizedFolderPath ) ;
303-
304- const sanitizedFolderUri = URI . file ( sanitizedFolderPath ) ;
305- return {
306- id : computeLocalDiskFolderId ( sanitizedFolderUri , fileStat ) ,
307- folder : sanitizedFolderUri
308- } ;
277+ const folder = folderUri . scheme === Schemas . file
278+ ? URI . file ( sanitizeFilePath ( folderUri . fsPath , process . env [ 'VSCODE_CWD' ] || process . cwd ( ) ) ) // For local: ensure path is absolute
279+ : folderUri ;
280+ const id = await resourceIdentityService . resolveResourceIdentity ( folderUri ) ;
281+ return { id, folder } ;
309282 } catch ( error ) {
310283 onUnexpectedError ( error ) ;
311284 }
312-
313285 return ;
314286 }
315287
0 commit comments