Skip to content

[Filesystem] [mirror] added "delete" option #6014

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

Closed
wants to merge 6 commits into from

Conversation

alexandre-melard
Copy link

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets:
Todo: -
License of the code: MIT
Documentation PR: symfony/symfony-docs#123

I added a "delete" option to the mirror function. If set to true, then
files present in target dir and not in origin dir will be removed.

Added also unit test for these feature.

I added a "delete" option to the mirror function. If set to TRUE, then
files present in target dir and not in origin dir will be removed
// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir)) {
if (isset($options['delete']) and $options['delete']) {
$l_iterator = $iterator;
Copy link
Member

Choose a reason for hiding this comment

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

We are using camelCased names, not underscores. And why l ?

Copy link
Author

Choose a reason for hiding this comment

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

I see your point, I didn't want to overwrite the $iterator variable so I had to use another name... the 'l' stands for 'local' I know it's unusual, I learned to use 'l_' at school and it's coming back from time to time... I will change it if you want 👍

Copy link
Member

Choose a reason for hiding this comment

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

Well, the variable name should follow the coding standards used in the project, and should be understandable by people who went to a different school than you 😄
So yeah, please rename it.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, done! I tried to push the change from work, but could not manage to
have git sending anything behind http proxy :(

On 15 November 2012 16:51, Christophe Coevoet notifications@github.comwrote:

In src/Symfony/Component/Filesystem/Filesystem.php:

  *
  * @throws IOException When file type is unknown
  */
 public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
 {
  •    $targetDir = rtrim($targetDir, '/\');
    
  •    $originDir = rtrim($originDir, '/\');
    
  •    // Iterate in destination folder to remove obsolete entries
    
  •    if ($this->exists($targetDir)) {
    
  •        if (isset($options['delete']) and $options['delete']) {
    
  •            $l_iterator = $iterator;
    

Well, the variable name should follow the coding standards used in the
project, and should be understandable by people who went to a different
school than you [image: 😄]
So yeah, please rename it.


Reply to this email directly or view it on GitHubhttps://github.com//pull/6014/files#r2140156.

$l_iterator  to $deleteIterator

// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir)) {
if (isset($options['delete']) and $options['delete']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please replace and by &&

Copy link
Author

Choose a reason for hiding this comment

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

I thought I good get rid of the && with an high level language :) At least with the 'and' your are not likely to put a '&' by mistake... But if it's standard thanks for the tips 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

and and && are not equivalent.

It doesn't matter in this case, but it could lead to weird behavior in other cases.

Copy link
Author

Choose a reason for hiding this comment

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

OMG, I didn't check that... I'm glad I post that PR, I'm learning a great deal of stuff !!
let's google now so I can check the diff :)

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I get it that the and as less precedence than the && and if I try:

$buf = 1;
$val = ($buf += 2 && $buf += 2);
$val is false

and

$buf = 1;
$val = ($buf += 2 and $buf += 2);
$val is true

Am I right?

Copy link
Author

Choose a reason for hiding this comment

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

in any case I would not trust precedence and add parenthesis... Hope it's coding standard too

@pborreli
Copy link
Contributor

Symfony2 code standard use lowercase true and false

and => &&
FALSE => false
' )' => ')'

// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir)) {
if (isset($options['delete']) && $options['delete']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be merged with the above if () statement.

@alexandre-melard
Copy link
Author

I have problem to believe that the last commit (merging two if together) was to blame for the segfault on travis...
when I run the unit testing on my machine, I get:

I'm using PHP 5.4.7 by the way...

Time: 2 seconds, Memory: 3.25Mb

OK, but incomplete or skipped tests!
Tests: 80, Assertions: 106, Skipped: 14.

@pborreli
Copy link
Contributor

Can you fix end-of-lines ?

@alexandre-melard
Copy link
Author

I put UNIX line feed and UTF8 charset

@alexandre-melard
Copy link
Author

Sorry, I add to clone the symfony repo with github and did small editing using pspad, I forgot to setup charset and line feed...

@fabpot fabpot closed this in b3c58e7 Dec 11, 2012
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.

6 participants