Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5e6f4d

Browse filesBrowse files
committed
feature #11857 [Filesystem] Check number of bytes copied. (skigun)
This PR was merged into the 2.6-dev branch. Discussion ---------- [Filesystem] Check number of bytes copied. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10838 | License | MIT | Doc PR | n/a This only test local files (because of `filesize`), wonder if we should include the remote files using `get_headers` in order to get the Content-length for example. However, it will perform an additional request... Here's a little benchmark for 500 copy from a remote origin file : - Standard without check -> Time: 47.34 seconds, Memory: 3.75Mb - Check with `get_headers` ->Time: 1.32 minutes, Memory: 3.75Mb Commits ------- 81eca38 [Filesystem] Check number of bytes copied.
2 parents a1f8d99 + 81eca38 commit e5e6f4d
Copy full SHA for e5e6f4d

File tree

Expand file treeCollapse file tree

1 file changed

+5
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-1
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ public function copy($originFile, $targetFile, $override = false)
6060
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
6161
}
6262

63-
stream_copy_to_stream($source, $target);
63+
$bytesCopied = stream_copy_to_stream($source, $target);
6464
fclose($source);
6565
fclose($target);
6666
unset($source, $target);
6767

6868
if (!is_file($targetFile)) {
6969
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
7070
}
71+
72+
if (stream_is_local($originFile) && $bytesCopied !== filesize($originFile)) {
73+
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s %g bytes copied".', $originFile, $targetFile, $bytesCopied), 0, null, $originFile);
74+
}
7175
}
7276
}
7377

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.