Commit 33b068c3 authored by Joe Hoyle's avatar Joe Hoyle
Browse files

Horrible hack to work around wp_upload_dir stating dirs all the time :/

parent 844b2202
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -306,6 +306,46 @@ class StreamWrapper
     */
    public function url_stat($path, $flags)
    {

        $pathinfo = pathinfo($path);

        /**
         * If the file is actually just a path to a directory
         * then return it as always existing. This is to work
         * around wp_upload_dir doing file_exists checks on 
         * the uploads directory on every page load
         */
        if ( ! strpos( $pathinfo['filename'], '.' ) ) {
            return array (
                0 => 0,
                'dev' => 0,
                1 => 0,
                'ino' => 0,
                2 => 16895,
                'mode' => 16895,
                3 => 0,
                'nlink' => 0,
                4 => 0,
                'uid' => 0,
                5 => 0,
                'gid' => 0,
                6 => -1,
                'rdev' => -1,
                7 => 0,
                'size' => 0,
                8 => 0,
                'atime' => 0,
                9 => 0,
                'mtime' => 0,
                10 => 0,
                'ctime' => 0,
                11 => -1,
                'blksize' => -1,
                12 => -1,
                'blocks' => -1,
            );
        }

        // Check if this path is in the url_stat cache
        if (isset(self::$nextStat[$path])) {
            return self::$nextStat[$path];
@@ -337,6 +377,8 @@ class StreamWrapper
                if (!$result['Contents'] && !$result['CommonPrefixes']) {
                    return $this->triggerError("File or directory not found: {$path}", $flags);
                }

                error_log(var_export($this->formatUrlStat($path), true));
                // This is a directory prefix
                return $this->formatUrlStat($path);
            }
@@ -358,6 +400,7 @@ class StreamWrapper
     */
    public function mkdir($path, $mode, $options)
    {
        error_log($path);
        $params = $this->getParams($path);
        $this->clearStatInfo($path);