ZF-3565: Zend_Cache_Backend_File fails to set directory permissions when hashed_directory_level > 1

Issue Type: Bug Created: 2008-07-03T04:08:29.000+0000 Last Updated: 2008-09-02T10:39:25.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: ChieftainY2k (chieftainy2k) Assignee: Fabien MARTY (fab) Tags: - Zend_Cache

Related issues: Attachments:



OS: Fedora Core release 6 (Zod) PHP: 5.1.6

Initial cache params:

$backendOptions parameter hashed_directory_level is set to be grater than 1 and hashed_directory_umask is set to 0777 (so that every user can read/write to the cache structure)


Because hash directory is created by giving mkdir and chmod the full path:

            mkdir($this->_path($id), $this->_options['hashed_directory_umask'], true);
            chmod($this->_path($id), $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)      

sometimes only the last directory within the path has the permission set correctly - all directories "in between" may have incorrect permissions set.


    $frontendOptions = array(
       'lifetime' => 3600,
       'automatic_serialization' => true,
       'automatic_cleaning_factor' => 0

    $backendOptions = array(
        'cache_dir' => '/tmp/leksyka_cache/',
        'read_control' => false,
        'read_control_type' => 'adler32',
        'hashed_directory_level' => 2,
        'cache_file_umask' => 0666,
        'hashed_directory_umask' => 0777,
        'file_name_prefix' => 'leksyka',
        'file_locking' => true

    // getting a Zend_Cache_Core object
    $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

    $this->_cache->save($data, $id, array() , 1000);

this creates a file:


with /tmp/leksyka_cache/leksyka--f permissions set to (0775/drwxrwxr-x)


Posted by ChieftainY2k (chieftainy2k) on 2008-07-03T05:47:17.000+0000

Here is proposal for the patch:

    if ($this->_options['hashed_directory_level'] > 0) {
        if (!is_writable($path)) {
            // maybe, we just have to build the directory structure

            // commented out: $res = @mkdir($path, $this->_options['hashed_directory_umask'], true);
            // commented out: @chmod($path, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)      

            //we crawl up the directory tree and check for missing directory nodes
            $pathCrawl = ($path[0]==DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : ".";
            $pathParts = explode(DIRECTORY_SEPARATOR,trim($path,DIRECTORY_SEPARATOR));
            foreach($pathParts as &$part)
                $pathCrawl .= ( $pathCrawl !=DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : "" ) . $part;
                if (!is_dir($pathCrawl))
                    $res = @mkdir($pathCrawl, $this->_options['hashed_directory_umask'], true);
                    if ($res) @chmod($pathCrawl, $this->_options['hashed_directory_umask']);
        if (!is_writable($path)) {
            return false;    

Posted by Fabien MARTY (fab) on 2008-07-05T05:50:16.000+0000

you are right

Posted by Fabien MARTY (fab) on 2008-07-28T13:08:17.000+0000

I just commited into SVN trunk a fix for this (in a different way), it seems to be ok for me

please reopen this issue if there is still a problem

thanks for the good report

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:25.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.