<commit_before><?php
/**
 * Class Minify_Cache_File
 * @package Minify
 */

class Minify_Cache_File {

    public function __construct($path = '', $fileLocking = false)
    {
        if (! $path) {
            $path = self::tmp();
        }
        $this->_locking = $fileLocking;
        $this->_path = $path;
    }

    /**
     * Write data to cache.
     *
     * @param string $id cache id (e.g. a filename)
     *
     * @param string $data
     *
     * @return bool success
     */
    public function store($id, $data)
    {
        $flag = $this->_locking
            ? LOCK_EX
            : null;
        $file = $this->_path . '/' . $id;
        if (is_file($file)) {
            @unlink($file);
        }
        if (! @file_put_contents($file, $data, $flag)) {
            $this->_log("Minify_Cache_File: Write failed to '$file'");
            return false;
        }
        // write control
        if ($data !== $this->fetch($id)) {
            @unlink($file);
            $this->_log("Minify_Cache_File: Post-write read failed for '$file'");
            return false;
        }
        return true;
    }

    /**
     * Get the size of a cache entry<commit_msg>Don't need to unlink file because file_put_contents will handle that. Also, don't return false after file_put_contents fails in case it creates a zero size file (use the existing "does the data match" check to ensure that the zero size file gets unlinked).<commit_after><?php
/**
 * Class Minify_Cache_File
 * @package Minify
 */

class Minify_Cache_File {

    public function __construct($path = '', $fileLocking = false)
    {
        if (! $path) {
            $path = self::tmp();
        }
        $this->_locking = $fileLocking;
        $this->_path = $path;
    }

    /**
     * Write data to cache.
     *
     * @param string $id cache id (e.g. a filename)
     *
     * @param string $data
     *
     * @return bool success
     */
    public function store($id, $data)
    {
        $flag = $this->_locking
            ? LOCK_EX
            : null;
        $file = $this->_path . '/' . $id;
        if (! @file_put_contents($file, $data, $flag)) {
            $this->_log("Minify_Cache_File: Write failed to '$file'");
        }
        // write control
        if ($data !== $this->fetch($id)) {
            @unlink($file);
            $this->_log("Minify_Cache_File: Post-write read failed for '$file'");
            return false;
        }
        return true;
    }

    /**
     * Get the size of a cache entry
{'fraction_non_alphanumeric': 0.13949780789159028, 'fraction_numerical': 0.0, 'mean_word_length': 1.7673649393605293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3686720', 'n_tokens_mistral': 767, 'n_tokens_neox': 756, 'n_words': 207}