Changing dirMode and fileMode for CAssetManager

I’ve added the following to my config file under “components”:




        'assetManager' => array(

            'newDirMode' => 0755,

            'newFileMode' => 0666,

        ),



However, asset directories are still being published as 0777 (the default). I am using Yii 1.1.9.

When I do a dump of Yii::app()->assetManager I can see the values are correct (as set in the config file).

Any ideas?

I still don’t know what was going on… to force this to work I ended up changing the hard-coded chmod values in the following files:

CAssetManager.php

CFileHelper.php

My development environment is Windows (where none of this is an issue) but my production environment is Linux (where this is an issue). I don’t have a way to debug in the production environment so I can’t figure out why the config values aren’t getting used. Something is not working as intended in the copyDirectoryRecursive method in CFileHelper.php. I’ve verified in my development environment that the following bit of code receives the values I would expect. Unfortunately I cannot debug this in the development environment.




		if(isset($options['newDirMode']))

			@chmod($dst,$options['newDirMode']);

		else

			@chmod($dst,0777);



copyDirectoryRecursive method from CFileHelper:




class CFileHelper

{

...

	/**

	 * Copies a directory.

	 * This method is mainly used by {@link copyDirectory}.

	 * @param string $src the source directory

	 * @param string $dst the destination directory

	 * @param string $base the path relative to the original source directory

	 * @param array $fileTypes list of file name suffix (without dot). Only files with these suffixes will be copied.

	 * @param array $exclude list of directory and file exclusions. Each exclusion can be either a name or a path.

	 * If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of

	 * '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude

	 * file or directory '$src/a/b'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.

	 * @param integer $level recursion depth. It defaults to -1.

	 * Level -1 means copying all directories and files under the directory;

	 * Level 0 means copying only the files DIRECTLY under the directory;

	 * level N means copying those directories that are within N levels.

	 * @param array $options additional options. The following options are supported:

	 * newDirMode - the permission to be set for newly copied directories (defaults to 0777);

	 * newFileMode - the permission to be set for newly copied files (defaults to the current environment setting).

	 */

	protected static function copyDirectoryRecursive($src,$dst,$base,$fileTypes,$exclude,$level,$options)

	{

		if(!is_dir($dst))

			mkdir($dst);

		if(isset($options['newDirMode']))

			@chmod($dst,$options['newDirMode']);

		else

			@chmod($dst,0777);

		$folder=opendir($src);

		while(($file=readdir($folder))!==false)

		{

			if($file==='.' || $file==='..')

				continue;

			$path=$src.DIRECTORY_SEPARATOR.$file;

			$isFile=is_file($path);

			if(self::validatePath($base,$file,$isFile,$fileTypes,$exclude))

			{

				if($isFile)

				{

					copy($path,$dst.DIRECTORY_SEPARATOR.$file);

					if(isset($options['newFileMode']))

						@chmod($dst.DIRECTORY_SEPARATOR.$file, $options['newFileMode']);

				}

				else if($level)

					self::copyDirectoryRecursive($path,$dst.DIRECTORY_SEPARATOR.$file,$base.'/'.$file,$fileTypes,$exclude,$level-1,$options);

			}

		}

		closedir($folder);

	}

...

}



could be that the web service user does not have permissions to run chmod