summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-07-14 17:03:36 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-07-15 13:56:02 +0200
commit40fe1275de1dcdb3f17027ceeaef19164956e146 (patch)
tree8c4278270d7a0ce5a6f5a4dd803d6f6b9835047a
parent6d7616587375b9e3cc3fae1aa15e33c9a711de06 (diff)
downloadnextcloud-server-40fe1275de1dcdb3f17027ceeaef19164956e146.tar.gz
nextcloud-server-40fe1275de1dcdb3f17027ceeaef19164956e146.zip
throw exception if file is to large for trash bin
-rw-r--r--apps/files_trashbin/appinfo/app.php2
-rw-r--r--apps/files_trashbin/lib/exceptions.php26
-rw-r--r--apps/files_trashbin/lib/trashbin.php24
3 files changed, 46 insertions, 6 deletions
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php
index 383115b8e63..718c2f45a34 100644
--- a/apps/files_trashbin/appinfo/app.php
+++ b/apps/files_trashbin/appinfo/app.php
@@ -1,6 +1,8 @@
<?php
$l = OC_L10N::get('files_trashbin');
+OC::$CLASSPATH['OCA\Files_Trashbin\Exceptions\CopyRecursiveException'] = 'files_trashbin/lib/exceptions.php';
+
// register hooks
\OCA\Files_Trashbin\Trashbin::registerHooks();
diff --git a/apps/files_trashbin/lib/exceptions.php b/apps/files_trashbin/lib/exceptions.php
new file mode 100644
index 00000000000..23e50293b77
--- /dev/null
+++ b/apps/files_trashbin/lib/exceptions.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * ownCloud - trash bin
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle schiessle@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Trashbin\Exceptions;
+
+class CopyRecursiveException extends \Exception {
+}
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 522f7d4b7e3..ee3969323cf 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -117,10 +117,18 @@ class Trashbin {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
- $sizeOfAddedFiles = self::copy_recursive('/files/' . $file_path, $trashPath, $view);
+ try {
+ $sizeOfAddedFiles = self::copy_recursive('/files/'.$file_path, $trashPath, $view);
+ } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
+ $sizeOfAddedFiles = false;
+ if ($view->file_exists($trashPath)) {
+ $view->deleteAll($trashPath);
+ }
+ \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
+ }
\OC_FileProxy::$enabled = $proxyStatus;
- if ($view->file_exists('files_trashbin/files/' . $filename . '.d' . $timestamp)) {
+ if ($sizeOfAddedFiles !== false) {
$size = $sizeOfAddedFiles;
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
$result = $query->execute(array($filename, $timestamp, $location, $user));
@@ -137,8 +145,6 @@ class Trashbin {
if ($user !== $owner) {
self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp);
}
- } else {
- \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
}
$userTrashSize += $size;
@@ -823,13 +829,19 @@ class Trashbin {
$size += self::copy_recursive($pathDir, $destination . '/' . $i['name'], $view);
} else {
$size += $view->filesize($pathDir);
- $view->copy($pathDir, $destination . '/' . $i['name']);
+ $result = $view->copy($pathDir, $destination . '/' . $i['name']);
+ if (!$result) {
+ throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException();
+ }
$view->touch($destination . '/' . $i['name'], $view->filemtime($pathDir));
}
}
} else {
$size += $view->filesize($source);
- $view->copy($source, $destination);
+ $result = $view->copy($source, $destination);
+ if (!$result) {
+ throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException();
+ }
$view->touch($destination, $view->filemtime($source));
}
return $size;