Skip to content
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

Merged
merged 5 commits into from Dec 1, 2012

Conversation

senz
Copy link
Contributor

@senz senz commented Aug 6, 2012

In case of dstDir deeper than 1 level we must create it recursively as CFileHelper::copyDirectory docblock says:

Copies a directory recursively as another.
If the destination directory does not exist, it will be created.

@qiangxue
Copy link
Member

qiangxue commented Aug 6, 2012

It's better to be done in copyDirectory() rather than copyDirectoryRecursive().
We also shouldn't care about umask() setting.

@ghost ghost assigned cebe Aug 6, 2012
@senz
Copy link
Contributor Author

senz commented Aug 7, 2012

@qiangxue ok, i will move whole block to copyDirectroy
umask affects mkdir, but ive just read about its problems with concurrency, so will change back to chmod.

* 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);
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space after commas.

@senz
Copy link
Contributor Author

senz commented Aug 9, 2012

@rawtaz where can i read projects CSC?

@samdark
Copy link
Member

samdark commented Aug 9, 2012

@senz I'm going to put these together as a wiki page soon. Currently there's no such document.

@rawtaz
Copy link
Contributor

rawtaz commented Aug 9, 2012

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).

@samdark
Copy link
Member

samdark commented Aug 9, 2012

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.

@rawtaz
Copy link
Contributor

rawtaz commented Aug 9, 2012

Issue #1179 can be used for discussions about the new wiki page. Thanks for setting up the wiki page @samdark.

@samdark
Copy link
Member

samdark commented Aug 9, 2012

Thanks.

@ghost ghost assigned samdark and cebe Sep 8, 2012
private static function mkdir($dst, $mode, $recursive)
{
$res = mkdir($dst, $mode, $recursive);
chmod($dst, $mode);
Copy link
Member

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"?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
@ghost ghost assigned samdark Oct 12, 2012
@samdark
Copy link
Member

samdark commented Oct 12, 2012

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:
Copy link
Member

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>

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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 :)

Copy link
Member

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.

@samdark samdark merged commit 2888b09 into yiisoft:master Dec 1, 2012
@samdark
Copy link
Member

samdark commented Dec 1, 2012

Thanks for working on it. Merged with some adjustments.

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

Successfully merging this pull request may close these issues.

None yet

7 participants