debt - introduce environment main service to have properties there exclusively

This commit is contained in:
Benjamin Pasero
2020-10-12 11:12:35 +02:00
parent 47116a8acd
commit ca4dd67abe
26 changed files with 98 additions and 68 deletions

View File

@@ -16,6 +16,7 @@ export class StorageDataCleaner extends Disposable {
private static readonly NON_EMPTY_WORKSPACE_ID_LENGTH = 128 / 4;
constructor(
private readonly backupWorkspacesPath: string,
@INativeEnvironmentService private readonly environmentService: INativeEnvironmentService
) {
super();
@@ -27,14 +28,17 @@ export class StorageDataCleaner extends Disposable {
let handle: NodeJS.Timeout | undefined = setTimeout(() => {
handle = undefined;
// Leverage the backup workspace file to find out which empty workspace is currently in use to
// determine which empty workspace storage can safely be deleted
readFile(this.environmentService.backupWorkspacesPath, 'utf8').then(contents => {
const workspaces = JSON.parse(contents) as IBackupWorkspacesFormat;
const emptyWorkspaces = workspaces.emptyWorkspaceInfos.map(info => info.backupFolder);
(async () => {
try {
// Leverage the backup workspace file to find out which empty workspace is currently in use to
// determine which empty workspace storage can safely be deleted
const contents = await readFile(this.backupWorkspacesPath, 'utf8');
// Read all workspace storage folders that exist
return readdir(this.environmentService.workspaceStorageHome.fsPath).then(storageFolders => {
const workspaces = JSON.parse(contents) as IBackupWorkspacesFormat;
const emptyWorkspaces = workspaces.emptyWorkspaceInfos.map(info => info.backupFolder);
// Read all workspace storage folders that exist
const storageFolders = await readdir(this.environmentService.workspaceStorageHome.fsPath);
const deletes: Promise<void>[] = [];
storageFolders.forEach(storageFolder => {
@@ -47,9 +51,11 @@ export class StorageDataCleaner extends Disposable {
}
});
return Promise.all(deletes);
});
}).then(null, onUnexpectedError);
await Promise.all(deletes);
} catch (error) {
onUnexpectedError(error);
}
})();
}, 30 * 1000);
this._register(toDisposable(() => {

View File

@@ -84,6 +84,7 @@ interface ISharedProcessInitData {
sharedIPCHandle: string;
args: NativeParsedArgs;
logLevel: LogLevel;
backupWorkspacesPath: string;
}
const eventPrefix = 'monacoworkbench';
@@ -262,7 +263,7 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
disposables.add(combinedDisposable(
instantiationService2.createInstance(NodeCachedDataCleaner),
instantiationService2.createInstance(LanguagePackCachedDataCleaner),
instantiationService2.createInstance(StorageDataCleaner),
instantiationService2.createInstance(StorageDataCleaner, initData.backupWorkspacesPath),
instantiationService2.createInstance(LogsDataCleaner),
userDataAutoSync
));