<commit_before><?php
class Kwf_Uploads_Row extends Kwf_Model_Proxy_Row
{
    protected function _deleteFile()
    {
        $filename = $this->getFileSource();
        if ($filename && is_file($filename)) {
            unlink($filename);
        }
    }

    protected function _putFileContents($contents)
    {
        $filename  = $this->getFileSource();
        $uploadsDir = $this->getModel()->getUploadDir() . '/' . substr($this->id, 0, 2);
        if (!is_dir($uploadsDir)) mkdir($uploadsDir);
        $handle = fopen($filename, "w");
        $pointer = 0;
        $length = 1024;
        $bytesWritten = 0;
        while ($contentPart = substr($contents, $pointer, $length)) {
            $bytesWritten += fwrite($handle, $contentPart);
            $pointer = $pointer+$length;
        }
        fclose($handle);
        if ($bytesWritten != strlen($contents)) {
            throw new Kwf_Exception("Writing file failed");
        }
    }

    public function writeFile($contents, $filename, $extension, $mimeType = null)
    {
        $this->filename = $filename;
        $this->extension = $extension;
        $mimeType = self::detectMimeType($mimeType, $contents);
        $this->mime_type = $mimeType;
        $this->md5_hash = md5($contents);
        $this->save();
        $this->_putFileContents($contents);
        return $this;
    }
<commit_msg>Check for dir and not for file<commit_after><?php
class Kwf_Uploads_Row extends Kwf_Model_Proxy_Row
{
    protected function _deleteFile()
    {
        $filename = $this->getFileSource();
        if ($filename && is_file($filename)) {
            unlink($filename);
        }
    }

    protected function _putFileContents($contents)
    {
        $filename  = $this->getFileSource();
        $uploadsDir = $this->getModel()->getUploadDir() . '/' . substr($this->id, 0, 2) . '/';
        if (!is_dir($uploadsDir)) mkdir($uploadsDir);
        $handle = fopen($filename, "w");
        $pointer = 0;
        $length = 1024;
        $bytesWritten = 0;
        while ($contentPart = substr($contents, $pointer, $length)) {
            $bytesWritten += fwrite($handle, $contentPart);
            $pointer = $pointer+$length;
        }
        fclose($handle);
        if ($bytesWritten != strlen($contents)) {
            throw new Kwf_Exception("Writing file failed");
        }
    }

    public function writeFile($contents, $filename, $extension, $mimeType = null)
    {
        $this->filename = $filename;
        $this->extension = $extension;
        $mimeType = self::detectMimeType($mimeType, $contents);
        $this->mime_type = $mimeType;
        $this->md5_hash = md5($contents);
        $this->save();
        $this->_putFileContents($contents);
        return $this;
    }

{'fraction_non_alphanumeric': 0.15216599927193303, 'fraction_numerical': 0.0072806698216235895, 'mean_word_length': 2.4221668742216687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1025888', 'n_tokens_mistral': 842, 'n_tokens_neox': 791, 'n_words': 160}