Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

file_exists Always return true even if file does not exist #50

Open
h3christophe opened this issue Apr 14, 2015 · 0 comments
Open

file_exists Always return true even if file does not exist #50

h3christophe opened this issue Apr 14, 2015 · 0 comments

Comments

@h3christophe
Copy link

The php function file_exists() uses the the stream wrapper function url_stat()
Unfortunately \ZendService\Amazon\S3\Stream function url_stat always return a value even if the file does not exists
It means that everytime you uses file_exists() it always return true .

I only tested using FakeS3 - which simulate an amazon s3 "server" https://github.com/jubos/fake-s3
So it might be related but looking at the url_stat function I am pretty certain this is not caused by FakeS3

    /**
     * Return array of URL variables
     *
     * @param  string $path
     * @param  integer $flags
     * @return array
     */
    public function url_stat($path, $flags)
    {
        $stat = array();
        $stat['dev'] = 0;
        $stat['ino'] = 0;
        $stat['mode'] = 0777;
        $stat['nlink'] = 0;
        $stat['uid'] = 0;
        $stat['gid'] = 0;
        $stat['rdev'] = 0;
        $stat['size'] = 0;
        $stat['atime'] = 0;
        $stat['mtime'] = 0;
        $stat['ctime'] = 0;
        $stat['blksize'] = 0;
        $stat['blocks'] = 0;
    $name = $this->_getNamePart($path);
    if(($slash = strchr($name, '/')) === false || $slash == strlen($name)-1) {
        /* bucket */
        $stat['mode'] |= 040000;
    } else {
        $stat['mode'] |= 0100000;
    }
           $info = $this->_getS3Client($path)->getInfo($name);
        if (!empty($info)) {
            $stat['size']  = $info['size'];
            $stat['atime'] = time();
            $stat['mtime'] = $info['mtime'];
        }
        return $stat;
    }

I believe it should be

public function url_stat($path, $flags) {
        $stat = array();
        $stat['dev'] = 0;
        $stat['ino'] = 0;
        $stat['mode'] = 0777;
        $stat['nlink'] = 0;
        $stat['uid'] = 0;
        $stat['gid'] = 0;
        $stat['rdev'] = 0;
        $stat['size'] = 0;
        $stat['atime'] = 0;
        $stat['mtime'] = 0;
        $stat['ctime'] = 0;
        $stat['blksize'] = 0;
        $stat['blocks'] = 0;

        $name = $this->_getNamePart($path);
        if (($slash = strchr($name, '/')) === false || $slash == strlen($name) - 1) {
            /* bucket */
            $stat['mode'] |= 040000;
        } else {
            $stat['mode'] |= 0100000;
        }

        $info = $this->_getS3Client($path)->getInfo($name);

        if (!empty($info)) {
            $stat['size'] = $info['size'];
            $stat['atime'] = time();
            $stat['mtime'] = $info['mtime'];
            return $stat;
        }

        return false;

    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant