10
import { IStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';
11
12
>
export async function getServiceMachineId(environmentService: IEnvironmentService, fileService: IFileService, storageService: IStorageService | undefined): Promise<string> {
serviceMachineId.ts
13
>
let uuid: string | null = storageService ? storageService.get('storage.serviceMachineId', StorageScope.APPLICATION) || null : null;
14
>
if (uuid) {
15
return uuid;
16
}
18
>
const contents = await fileService.readFile(environmentService.serviceMachineIdResource);
19
const value = contents.value.toString();
21
>
} catch (e) {
22
>
uuid = null;
23
>
}
24
>
25
>
if (!uuid) {
26
>
uuid = generateUuid();
27
>
try {
28
>
await fileService.writeFile(environmentService.serviceMachineIdResource, VSBuffer.fromString(uuid));
29
>
} catch (error) {
30
//noop
31
}
33
>
34
>
storageService?.store('storage.serviceMachineId', uuid, StorageScope.APPLICATION, StorageTarget.MACHINE);
35
>
36
>
return uuid;
37
>
}