<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { join, dirname, basename } from 'vs/base/common/path';
import { readdir, rimraf } from 'vs/base/node/pfs';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';

export class LogsDataCleaner extends Disposable {

	constructor(
		@IEnvironmentService private readonly environmentService: IEnvironmentService
	) {
		super();

		this.cleanUpOldLogsSoon();
	}

	private cleanUpOldLogsSoon(): void {
		let handle: NodeJS.Timeout | undefined = setTimeout(() => {
			handle = undefined;

			const currentLog = basename(this.environmentService.logsPath);
			const logsRoot = dirname(this.environmentService.logsPath);

			readdir(logsRoot).then(children => {
				const allSessions = children.filter(name => /^\d{8}T\d{6}$/.test(name));
				const oldSessions = allSessions.sort().filter((d, i) => d !== currentLog);
				const toDelete = oldSessions.slice(0, Math.max(0, oldSessions.length - 49));

				return Promise.all(toDelete.map(name => rimraf(join(logsRoot, name))));
			}).then(null, onUnexpectedError);
		}, 10 * 1000);

		this._register(toDisposable(() => {
			if (handle) {
				clearTimeout(handle);
				handle = undefined;
			}
		}));
	}
}
<commit_msg>undo change in shared process<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { join, dirname, basename } from 'vs/base/common/path';
import { readdir, rimraf } from 'vs/base/node/pfs';
import { onUnexpectedError } from 'vs/base/common/errors';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';

export class LogsDataCleaner extends Disposable {

	constructor(
		@IEnvironmentService private readonly environmentService: IEnvironmentService
	) {
		super();

		this.cleanUpOldLogsSoon();
	}

	private cleanUpOldLogsSoon(): void {
		let handle: NodeJS.Timeout | undefined = setTimeout(() => {
			handle = undefined;

			const currentLog = basename(this.environmentService.logsPath);
			const logsRoot = dirname(this.environmentService.logsPath);

			readdir(logsRoot).then(children => {
				const allSessions = children.filter(name => /^\d{8}T\d{6}$/.test(name));
				const oldSessions = allSessions.sort().filter((d, i) => d !== currentLog);
				const toDelete = oldSessions.slice(0, Math.max(0, oldSessions.length - 9));

				return Promise.all(toDelete.map(name => rimraf(join(logsRoot, name))));
			}).then(null, onUnexpectedError);
		}, 10 * 1000);

		this._register(toDisposable(() => {
			if (handle) {
				clearTimeout(handle);
				handle = undefined;
			}
		}));
	}
}

{'fraction_non_alphanumeric': 0.2320637732506643, 'fraction_numerical': 0.006790670209625037, 'mean_word_length': 2.6627027027027026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695151', 'n_tokens_mistral': 1032, 'n_tokens_neox': 914, 'n_words': 216}