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

'use strict';

import assert = require('assert');
import os = require('os');

import path = require('path');
import fs = require('fs');

import uuid = require('vs/base/common/uuid');
import strings = require('vs/base/common/strings');
import extfs = require('vs/base/node/extfs');
import { onError } from 'vs/base/test/common/utils';
import { Readable } from 'stream';
import { isLinux } from 'vs/base/common/platform';

const ignore = () => { };

const mkdirp = (path: string, mode: number, callback: (error) => void) => {
	extfs.mkdirp(path, mode).done(() => callback(null), error => callback(error));
};

const chunkSize = 64 * 1024;
const readError = 'Error while reading';
function toReadable(value: string, throwError?: boolean): Readable {
	const totalChunks = Math.ceil(value.length / chunkSize);
	const stringChunks: string[] = [];

	for (let i = 0, j = 0; i < totalChunks; ++i, j += chunkSize) {
		stringChunks[i] = value.substr(j, chunkSize);
	}

	let counter = 0;
	return new Readable({
		read: function () {
			if (throwError) {
				this.emit('error', new Error(readError));
			}

			let res: string;
			let canPush = true;
			while (canPush && (res = stringChunks[counter++])) {
				canPush = this.push(res);
			}

			// EOS
			if (!res) {
				this.push(null);
			}
		},
		encoding: 'utf8'
	});
}

suite('Extfs', () => {

	test('mkdirp', function (done: () => void) {
		const id = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id);
		const newDir = path.join(parentDir, 'extfs', id);

		mkdirp(newDir, 493, error => {
			if (error) {
				return onError(error, done);
			}

			assert.ok(fs.existsSync(newDir));

			extfs.del(parentDir, os.tmpdir(), done, ignore);
		}); // 493 = 0755
	});

	test('stat link', function (done: () => void) {
		const id1 = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id1);
		const directory = path.join(parentDir, 'extfs', id1);
<commit_msg>Symlinks are not the same on win, and we can not create them programitically without adming privileges<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import assert = require('assert');
import os = require('os');

import path = require('path');
import fs = require('fs');

import uuid = require('vs/base/common/uuid');
import strings = require('vs/base/common/strings');
import extfs = require('vs/base/node/extfs');
import { onError } from 'vs/base/test/common/utils';
import { Readable } from 'stream';
import { isLinux, isWindows } from 'vs/base/common/platform';

const ignore = () => { };

const mkdirp = (path: string, mode: number, callback: (error) => void) => {
	extfs.mkdirp(path, mode).done(() => callback(null), error => callback(error));
};

const chunkSize = 64 * 1024;
const readError = 'Error while reading';
function toReadable(value: string, throwError?: boolean): Readable {
	const totalChunks = Math.ceil(value.length / chunkSize);
	const stringChunks: string[] = [];

	for (let i = 0, j = 0; i < totalChunks; ++i, j += chunkSize) {
		stringChunks[i] = value.substr(j, chunkSize);
	}

	let counter = 0;
	return new Readable({
		read: function () {
			if (throwError) {
				this.emit('error', new Error(readError));
			}

			let res: string;
			let canPush = true;
			while (canPush && (res = stringChunks[counter++])) {
				canPush = this.push(res);
			}

			// EOS
			if (!res) {
				this.push(null);
			}
		},
		encoding: 'utf8'
	});
}

suite('Extfs', () => {

	test('mkdirp', function (done: () => void) {
		const id = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id);
		const newDir = path.join(parentDir, 'extfs', id);

		mkdirp(newDir, 493, error => {
			if (error) {
				return onError(error, done);
			}

			assert.ok(fs.existsSync(newDir));

			extfs.del(parentDir, os.tmpdir(), done, ignore);
		}); // 493 = 0755
	});

	test('stat link', function (done: () => void) {
		if (isWindows) {
			// Symlinks are not the same on win, and we can not create them programitically without admin privileges
			return done();
		}

		const id1 = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id1);
		const directory = path.join(parentDir, 'extfs', id1);

{'fraction_non_alphanumeric': 0.23288232882328824, 'fraction_numerical': 0.00943009430094301, 'mean_word_length': 2.7733952049497295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2754237', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1498, 'n_words': 420}