Skip to content

Commit 311e627

Browse files
committed
bug symfony#23398 [Filesystem] Dont copy perms when origin is remote (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Filesystem] Dont copy perms when origin is remote | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#23312 | License | MIT | Doc PR | - Commits ------- 7b44221 [Filesystem] Dont copy perms when origin is remote
2 parents 39fc4dd + 7b44221 commit 311e627

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class Filesystem
3737
*/
3838
public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
3939
{
40-
if (stream_is_local($originFile) && !is_file($originFile)) {
40+
$originIsLocal = stream_is_local($originFile) || 0 === stripos($originFile, 'file://');
41+
if ($originIsLocal && !is_file($originFile)) {
4142
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
4243
}
4344

@@ -68,11 +69,13 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
6869
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
6970
}
7071

71-
// Like `cp`, preserve executable permission bits
72-
@chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));
72+
if ($originIsLocal) {
73+
// Like `cp`, preserve executable permission bits
74+
@chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));
7375

74-
if (stream_is_local($originFile) && $bytesCopied !== ($bytesOrigin = filesize($originFile))) {
75-
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
76+
if ($bytesCopied !== $bytesOrigin = filesize($originFile)) {
77+
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
78+
}
7679
}
7780
}
7881
}

0 commit comments

Comments
 (0)