8000 [Filesystem] Dont copy perms when origin is remote · symfony/symfony@7b44221 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b44221

Browse files
[Filesystem] Dont copy perms when origin is remote
1 parent 139e3ea commit 7b44221

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)
0