Skip to content

[Filesystem] mirror - fix copying content with same name as source/target. #23473

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 4 commits into from

Conversation

gitlost
Copy link
Contributor

@gitlost gitlost commented Jul 11, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23472
License MIT
Doc PR

Uses substr() and lengths in Filesystem::mirror() rather than str_replace() to avoid multiple replacements.

@xabbuh
Copy link
Member

xabbuh commented Jul 12, 2017

I would split the test case into two (one with the delete option, the other one without it) to make them independent from each other.

@nicolas-grekas
Copy link
Member

@gitlost could you please split the test case in two as suggested by @xabbuh ?

$this->assertFileExists($targetPath.'source');
$this->assertFileExists($targetPath.'target');

chdir($oldPath);
Copy link
Member

Choose a reason for hiding this comment

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

this can be removed now

$this->assertFileExists($targetPath.'source');
$this->assertFileNotExists($targetPath.'target');

chdir($oldPath);
Copy link
Member

Choose a reason for hiding this comment

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

same here

{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

$oldPath = getcwd();
Copy link
Member

Choose a reason for hiding this comment

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

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you be less cryptic please? What isn't needed and why? Ditto for other comments.

Copy link
Member

Choose a reason for hiding this comment

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

We do not need the chdir() call after the assertions at the end of both methods. Therefore, we can also removed the $oldPath variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you give a reason please? The save/restore chdir()s are following the same pattern as the existing tests testFilesExistsFails() and testMirrorCopiesRelativeLinkedContents() and it seems good practice to leave things as you find them.

Copy link
Member

Choose a reason for hiding this comment

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

Doing clean up work after performing assertions is not reliable. As soon as one of the assertions fails clean up work will not happen anymore. So what we could is remember the current directory inside the base class' setUp() method and restore it in tearDown().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing clean up work after performing assertions is not reliable.

True, I've moved them to directly before and after the call to mirror().

So what we could is...

Another PR perhaps?

{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

$oldPath = getcwd();
Copy link
Member

Choose a reason for hiding this comment

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

not needed

@xabbuh
Copy link
Member

xabbuh commented Sep 13, 2017

ping @symfony/deciders

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

@gitlost thanks for fixing this bug ... and congrats on your first Symfony contribution!

@fabpot
Copy link
Member

fabpot commented Sep 13, 2017

Thank you @gitlost.

fabpot added a commit that referenced this pull request Sep 13, 2017
…s source/target. (gitlost)

This PR was squashed before being merged into the 2.7 branch (closes #23473).

Discussion
----------

[Filesystem] mirror - fix copying content with same name as source/target.

| Q             | A
| ------------- | ---
| Branch?       |  2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23472
| License       | MIT
| Doc PR        |

Uses `substr()` and lengths in `Filesystem::mirror()` rather than `str_replace()` to avoid multiple replacements.

Commits
-------

b524c84 [Filesystem] mirror - fix copying content with same name as source/target.
@fabpot fabpot closed this Sep 13, 2017
This was referenced Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants