aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-09-26 10:53:43 +0200
committerGitHub <noreply@github.com>2016-09-26 10:53:43 +0200
commit244de6451b22a1288d3ef698f48fb9c4e78bf15f (patch)
tree4d8ef52796d9249ebbccac91a3bf922b5637f668
parent9e91a76b30d9232add8bf2a8fd37572fb21b1207 (diff)
parent19ad11cce436244e48f7a975113a7f246d9e6842 (diff)
downloadnextcloud-server-244de6451b22a1288d3ef698f48fb9c4e78bf15f.tar.gz
nextcloud-server-244de6451b22a1288d3ef698f48fb9c4e78bf15f.zip
Merge pull request #1507 from nextcloud/more-error-handling-in-copyr
Graceful error handling and logging
-rw-r--r--lib/private/legacy/util.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php
index 04dcb8fc896..cb52949779f 100644
--- a/lib/private/legacy/util.php
+++ b/lib/private/legacy/util.php
@@ -336,7 +336,16 @@ class OC_Util {
* @return void
*/
public static function copyr($source, \OCP\Files\Folder $target) {
+ $logger = \OC::$server->getLogger();
+
+ // Verify if folder exists
$dir = opendir($source);
+ if($dir === false) {
+ $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']);
+ return;
+ }
+
+ // Copy the files
while (false !== ($file = readdir($dir))) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (is_dir($source . '/' . $file)) {
@@ -344,7 +353,13 @@ class OC_Util {
self::copyr($source . '/' . $file, $child);
} else {
$child = $target->newFile($file);
- stream_copy_to_stream(fopen($source . '/' . $file,'r'), $child->fopen('w'));
+ $sourceStream = fopen($source . '/' . $file, 'r');
+ if($sourceStream === false) {
+ $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']);
+ closedir($dir);
+ return;
+ }
+ stream_copy_to_stream($sourceStream, $child->fopen('w'));
}
}
}