<commit_before><?php
include_once 'classes/UploadedFile.class.php';
include_once 'includes/settings.inc.php';
include_once 'includes/database.inc.php';


/**
 * Generates a name for the file, retrying until we get an unused one 
 *
 * @param UploadedFile $file
 * @return string
 */
function generate_name ($file) {
	// We start at N retries, and --N until we give up
	$tries = POMF_FILES_RETRIES;
	// We rip out the extension using pathinfo
	// TODO: figure out a solution for .tar.gz and similar files? This has now been ghetto fixed!
	$ext = pathinfo($file->name, PATHINFO_EXTENSION);
	// Take the first 3 chars of the CRC32 checksum
	$hashchunk = substr($file->get_crc32(), 0, 3);
	do {
		// If we run out of tries, throw an exception.  Should be caught and JSONified.
		if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name');

		// TODO: come up with a better name generating algorithm
		$newname  = '';                                  // Filename Generator:
		$newname .= chr(mt_rand(ord("a"), ord("z")));    // + random lowercase letter
		$newname .= $hashchunk;                          // + first 3 of crc32b checksum
		$newname .= chr(mt_rand(ord("a"), ord("z")));    // + random lowercase letter
		
		// To add a dot or not to add a dot ghetto style
                $ass = pathinfo($file->name, PATHINFO_FILENAME);
                $pos = strrpos($ass, '.');
                if ($pos === false) {
                // Nothing
                }else{
                $newname .= '.' . $ext;
                }


	} while (file_exists(POMF_FILES_ROOT . $newname)); // TODO: check the database instead?

	return $newname;
}


/**
 * Handles the uploading and db entry for a file
 *
 * @param UploadedFile $file
 * @return array
 */
function upload_file ($file) {
	global $db;<commit_msg>dot dot dot dots and more dots<commit_after><?php
include_once 'classes/UploadedFile.class.php';
include_once 'includes/settings.inc.php';
include_once 'includes/database.inc.php';


/**
 * Generates a name for the file, retrying until we get an unused one 
 *
 * @param UploadedFile $file
 * @return string
 */
function generate_name ($file) {
	// We start at N retries, and --N until we give up
	$tries = POMF_FILES_RETRIES;
	// We rip out the extension using pathinfo
	// TODO: figure out a solution for .tar.gz and similar files? This has now been ghetto fixed, read below!
	$ext = pathinfo($file->name, PATHINFO_EXTENSION);
	// Take the first 3 chars of the CRC32 checksum
	$hashchunk = substr($file->get_crc32(), 0, 3);
	do {
		// If we run out of tries, throw an exception.  Should be caught and JSONified.
		if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name');

		// TODO: come up with a better name generating algorithm
		$newname  = '';                                  // Filename Generator:
		$newname .= chr(mt_rand(ord("a"), ord("z")));    // + random lowercase letter
		$newname .= $hashchunk;                          // + first 3 of crc32b checksum
		$newname .= chr(mt_rand(ord("a"), ord("z")));    // + random lowercase letter
		
		// To add a dot or not after a file which has no extension, ghetto style naturally!
                $ass = pathinfo($file->name, PATHINFO_FILENAME);
                $pos = strrpos($ass, '.');
                if ($pos === false) {
                // Nothing
                }else{
                $newname .= '.' . $ext;
                }


	} while (file_exists(POMF_FILES_ROOT . $newname)); // TODO: check the database instead?

	return $newname;
}


/**
 * Handles the uploading and db entry for a file
 *
 * @param UploadedFile $file
 * @return array
 */
function upload_file ($file) {
	global $db;
{'fraction_non_alphanumeric': 0.12635281385281386, 'fraction_numerical': 0.005952380952380952, 'mean_word_length': 2.4583723105706268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1410409', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1126, 'n_words': 395}