New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CFileHelper::copyDirectory recursive mkdir. #1146
CFileHelper::copyDirectory recursive mkdir. #1146
Conversation
It's better to be done in copyDirectory() rather than copyDirectoryRecursive(). |
@qiangxue ok, i will move whole block to copyDirectroy |
* dir access mode is set by chmod, again (note: if dst is created recursively, then only last dir will have newDirMode access).
@@ -56,6 +56,8 @@ public static function copyDirectory($src,$dst,$options=array()) | |||
$exclude=array(); | |||
$level=-1; | |||
extract($options); | |||
if(!is_dir($dst)) self::mkdir($dst, self::getModeFromOptions($options), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline between if() and the following statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space after commas.
@rawtaz where can i read projects CSC? |
@senz I'm going to put these together as a wiki page soon. Currently there's no such document. |
The current source code is the best option for now :) I use it quite a lot to search for patterns when I want to know how something is usually done, for example the PHPdoc stuff (whether to write boolean or bool, etc). |
https://github.com/yiisoft/yii/wiki/Core-framework-code-style here it is. Feel free to edit it adding facts from current source code and examples. |
Thanks. |
private static function mkdir($dst, $mode, $recursive) | ||
{ | ||
$res = mkdir($dst, $mode, $recursive); | ||
chmod($dst, $mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doing chmod
here? What is "concurrent compatibility"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read on PHP.net that using mkdir mode can cause troubles with fpm. If I'm understanding your question right.
Alexander Makarov notifications@github.com wrote:
- /**
\* Creates directory for $dst path with $mode and $recursive creation is allowed.
\* For concurrent compatibility chmod is used instead of mkdir's $mode.
*
\* @static
\* @param string $dst path to be created
\* @param integer $mode access bitmask
\* @param boolean $recursive
\* @return boolean result of mkdir
\* @see mkdir
*/
- private static function mkdir($dst, $mode, $recursive)
- {
$res = mkdir($dst, $mode, $recursive);
chmod($dst, $mode);
Why doing
chmod
here?
Reply to this email directly or view it on GitHub:
https://github.com/yiisoft/yii/pull/1146/files#r1810581
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of troubles exactly? mkdir
respects sticky flag so probably chmod
is necessary but you're calling it once and not for each dir in the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, troubles was with umask: http://www.php.net/manual/en/function.umask.php (ive used it in other revisions).
I guess Ive just copied this from other yii code, suggesting that this is some kind of style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, chmod is not affected with umask. so there are no side effects
* newDirMode correctly setted on recursive creation of dst dir.
Thanks for the test. Will check it soon. |
…sive_copy_fix Conflicts: tests/framework/utils/CFileHelperTest.php
@@ -31,7 +31,7 @@ public static function getExtension($path) | |||
|
|||
/** | |||
* Copies a directory recursively as another. | |||
* If the destination directory does not exist, it will be created. | |||
* If the destination directory does not exist, it will be created recursively. | |||
* @param string $src the source directory | |||
* @param string $dst the destination directory | |||
* @param array $options options for directory copy. Valid options are: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation for mode options is missing in this method, please copy them from protected method copyDirectoryRecursive
.
* <li>newDirMode - the permission to be set for newly copied directories (defaults to 0777);</li>
* <li>newFileMode - the permission to be set for newly copied files (defaults to the current environment setting).</li>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just noticed that all the options described in the docs of copyDirectory
are completely ignored...!? Has nobody noticed that until now, or am I overlooking something? @yiisoft/core-developers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignored?
they get extracted on the line 57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh damn, thanks for opening my eyes @mdomba :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are working fine as @mdomba mentioned. Used this method just recently.
Thanks for working on it. Merged with some adjustments. |
In case of dstDir deeper than 1 level we must create it recursively as CFileHelper::copyDirectory docblock says: