<commit_before>// fs.writeFile that's safe for simultaneous calls for same file.
// In such event write that is ongoing is exited and new one is initialized

'use strict';

var fs      = require('fs')
  , resolve = require('path').resolve

  , next, writeAll, cache = {};

next = function (path) {
	var args;
	if (cache[path] === true) {
		delete cache[path];
	} else {
		args = cache[path];
		delete cache[path];
		exports.apply(null, args);
	}
};

writeAll = function (path, fd, buffer, offset, length, callback) {
	// write(fd, buffer, offset, length, position, callback)
	fs.write(fd, buffer, offset, length, offset, function(writeErr, written) {
		if (writeErr) {
			fs.close(fd, function() {
				if (callback) callback(writeErr);
				next(path);
			});
		} else {
			if ((written === length) || (cache[path] !== true)) {
				fs.close(fd, function () {
					if (callback) callback.apply(null, arguments);
					next(path);
				});
			} else {
				writeAll(path, fd, buffer, offset + written, length - written, callback);
			}
		}
	});
};

exports = module.exports = function (path, data, encoding_, callback) {
	var encoding, callback_;
	path = resolve(String(path));
	if (cache[path]) {
		cache[path] = arguments;
		return;
	}
	cache[path] = true;

	encoding = (typeof(encoding_) == 'string' ? encoding_ : 'utf8');
	callback_ = arguments[arguments.length - 1];
	callback = (typeof(callback_) == 'function' ? callback_ : null);
	fs.open(path, 'w', 438 /*=0666*/, function (openErr, fd) {
		if (openErr) {
			if (callback) callback(openErr);
			next(path);
		} else  if (cache[path] === true) {
			var buffer = Buffer.isBuffer(data) ? data : new Buffer('' + data,
				encoding);
			writeAll(path, fd, buffer, 0, buffer.length, callback);
		} else {
			fs.close(fd, function () {
				if (callback) callback.apply(null, arguments);
				next(path);
			});
		}
	});
};
<commit_msg>Invoke callbacks of overriden calls<commit_after>// fs.writeFile that's safe for simultaneous calls for same file.
// In such event write that is ongoing is exited and new one is initialized

'use strict';

var fs      = require('fs')
  , resolve = require('path').resolve

  , next, writeAll, cache = {};

next = function (path) {
	var args;
	if (cache[path] === true) {
		delete cache[path];
	} else {
		args = cache[path];
		delete cache[path];
		exports.apply(null, args);
	}
};

writeAll = function (path, fd, buffer, offset, length, callback) {
	// write(fd, buffer, offset, length, position, callback)
	fs.write(fd, buffer, offset, length, offset, function(writeErr, written) {
		if (writeErr) {
			fs.close(fd, function() {
				if (callback) callback(writeErr);
				next(path);
			});
		} else {
			if ((written === length) || (cache[path] !== true)) {
				fs.close(fd, function () {
					if (callback) callback.apply(null, arguments);
					next(path);
				});
			} else {
				writeAll(path, fd, buffer, offset + written, length - written, callback);
			}
		}
	});
};

exports = module.exports = function (path, data, encoding_, callback) {
	var encoding, callback_;
	path = resolve(String(path));
	if (cache[path]) {
		if (cache[path] !== true) {
			callback_ = cache[path][cache[path].length - 1];
			if (typeof callback_ == 'function') {
				callback_(null);
			}
		}
		cache[path] = arguments;
		return;
	}
	cache[path] = true;

	encoding = (typeof(encoding_) == 'string' ? encoding_ : 'utf8');
	callback_ = arguments[arguments.length - 1];
	callback = (typeof(callback_) == 'function' ? callback_ : null);
	fs.open(path, 'w', 438 /*=0666*/, function (openErr, fd) {
		if (openErr) {
			if (callback) callback(openErr);
			next(path);
		} else  if (cache[path] === true) {
			var buffer = Buffer.isBuffer(data) ? data : new Buffer('' + data,
				encoding);
			writeAll(path, fd, buffer, 0, buffer.length, callback);
		} else {
			fs.close(fd, function () {
				if (callback) callback.apply(null, arguments);
				next(path);
			});
		}
	});
};

{'fraction_non_alphanumeric': 0.17026683608640406, 'fraction_numerical': 0.005336721728081322, 'mean_word_length': 3.582072176949942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '617639', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1300, 'n_words': 361}