8000 [Filesystem | WCM] 9339 fix stat on url for filesystem copy by cordoval · Pull Request #9899 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Filesystem | WCM] 9339 fix stat on url for filesystem copy #9899

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function copy($originFile, $targetFile, $override = false)

$this->mkdir(dirname($targetFile));

if (!$override && is_file($targetFile)) {
if (!$override && is_file($targetFile) && null == parse_url($originFile, PHP_URL_HOST)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be null === blablabla IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, sending the PR, thank you chief @stloyd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
Expand Down
15 changes: 14 additions & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
}

public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToNotCopy()
{
$sourceFilePath = 'http://symfony.com/images/common/logo/logo_symfony_header.png';
$targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'copy_target_file';

file_put_contents($targetFilePath, 'TARGET FILE');

$this->filesystem->copy($sourceFilePath, $targetFilePath, false);

$this->assertFileExists($targetFilePath);
$this->assertEquals(file_get_contents($sourceFilePath), file_get_contents($targetFilePath));
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... assertStringEqualsFile() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1) Symfony\Component\Filesystem\Tests\FilesystemTest::testCopyForOriginUrlsAndExistingLocalFileDefaultsToNotCopy
Failed asserting that file "http://symfony.com/images/common/logo/logo_symfony_header.png" exists.

/Users/cordoval/Sites/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php:181

is not for files on the web

with

$this->assertStringEqualsFile($sourceFilePath, file_get_contents($targetFilePath));

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH. I'm not sure it's good to try to download files from remote servers anyway...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is not good, but there is not another way when testing this functionality, these and others are the slowest tests ever that make symfony test suite very slow

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO better approach would be like with i.e. Behat, start server on Travis-CI (Apache, nginx, whatever...) and give fixtures to be downloaded, it would be for sure more safe, and maybe even faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great call, creating the ticket to be worked on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

public function testMkdirCreatesDirectoriesRecursively()
{
$directory = $this->workspace
Expand Down Expand Up @@ -336,7 +349,7 @@ public function testRemoveCleansInvalidLinks()

mkdir($basePath);
mkdir($basePath.'dir');
// create symlink to unexisting file
// create symlink to nonexistent file
@symlink($basePath.'file', $basePath.'link');

$this->filesystem->remove($basePath);
Expand Down
0