<commit_before><?php
namespace wcf\system\devtools\package;
use wcf\system\io\Tar;

/**
 * Specialized implementation to emulate a regular package installation.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Devtools\Package
 * @since       3.1
 */
class DevtoolsTar extends Tar {
	/**
	 * list of virtual files
	 * @var string[]
	 */
	protected $files = [];
	
	/** @noinspection PhpMissingParentConstructorInspection @inheritDoc */
	public function __construct(array $files) {
		$this->files = $files;
	}
	
	/**
	 * Resets the internal file list for re-use, because the devtools use
	 * the same instance over and over to avoid some otherwise awkward
	 * changes to the code. 
	 */
	public function reset() {
		$this->contentList = $this->files = [];
		$this->read = false;
	}
	
	/**
	 * Registers a new file in the virtual file list.
	 * 
	 * @param       string          $filename
	 * @param       string          $fullPath
	 */
	public function registerFile($filename, $fullPath) {
		$this->files[$filename] = $fullPath;
	}
	
	/**
	 * @inheritDoc
	 */
	public function getIndexByFilename($filename) {
		return (isset($this->files[$filename]) ? $filename : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function extractToString($index) {
		if (!isset($this->files[$index])) {
			throw new \RuntimeException("DevtoolsTar does not permit reading any files except for the explicitly registered ones.");
		}
		
		return file_get_contents($this->files[$index]);
	}
	
	/**
	 * @inheritDoc
	 */
	public function extract($index, $destination) {
		copy($this->files[$index], $destination);
	}
	
	/**
	 * @inheritDoc
	 */
	public function getContentList() {
		if (!$this->read) {
			foreach ($this->files as $filename => $fullPath) {
				if (strpos($filename, '/') !== false) {
					$directory = dirname($filename) . '/';
					if (!isset($this->contentList[$directory])) {
						$this->contentList[$directory] = [
							'filename' => $directory,
							'type' => 'folder'
						];
					}
				}
				
				$this->contentList[$filename] = [<commit_msg>Fix symlink issue during synchronisation of file pip<commit_after><?php
namespace wcf\system\devtools\package;
use wcf\system\io\Tar;

/**
 * Specialized implementation to emulate a regular package installation.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Devtools\Package
 * @since       3.1
 */
class DevtoolsTar extends Tar {
	/**
	 * list of virtual files
	 * @var string[]
	 */
	protected $files = [];
	
	/** @noinspection PhpMissingParentConstructorInspection @inheritDoc */
	public function __construct(array $files) {
		$this->files = $files;
	}
	
	/**
	 * Resets the internal file list for re-use, because the devtools use
	 * the same instance over and over to avoid some otherwise awkward
	 * changes to the code. 
	 */
	public function reset() {
		$this->contentList = $this->files = [];
		$this->read = false;
	}
	
	/**
	 * Registers a new file in the virtual file list.
	 * 
	 * @param       string          $filename
	 * @param       string          $fullPath
	 */
	public function registerFile($filename, $fullPath) {
		$this->files[$filename] = $fullPath;
	}
	
	/**
	 * @inheritDoc
	 */
	public function getIndexByFilename($filename) {
		return (isset($this->files[$filename]) ? $filename : false);
	}
	
	/**
	 * @inheritDoc
	 */
	public function extractToString($index) {
		if (!isset($this->files[$index])) {
			throw new \RuntimeException("DevtoolsTar does not permit reading any files except for the explicitly registered ones.");
		}
		
		return file_get_contents($this->files[$index]);
	}
	
	/**
	 * @inheritDoc
	 */
	public function extract($index, $destination) {
		// The source file is empty, if the file is a symlink, which yield to an error.
		if (empty($this->files[$index])) return;
		
		copy($this->files[$index], $destination);
	}
	
	/**
	 * @inheritDoc
	 */
	public function getContentList() {
		if (!$this->read) {
			foreach ($this->files as $filename => $fullPath) {
				if (strpos($filename, '/') !== false) {
					$directory = dirname($filename) . '/';
					if (!isset($this->contentList[$directory])) {
						$this->contentList[$directory] = [
							'filename' => $directory,
							'type' => 'folder'
						];
					}
				}
				
				$this->contentList[$filename] = [
{'fraction_non_alphanumeric': 0.1488003521901827, 'fraction_numerical': 0.004402377283733216, 'mean_word_length': 3.211306765523633, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 42, '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': '4825621', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1345, 'n_words': 360}