[Pkg-owncloud-commits] [owncloud] 28/70: throw exception if file is to large for trash bin

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:40:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v6.0.5RC1
in repository owncloud.

commit afa8006d7ccf0d2d9eb278bc769b64a6d8cd8f01
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Mon Jul 14 17:03:36 2014 +0200

    throw exception if file is to large for trash bin
---
 apps/files_trashbin/appinfo/app.php    |  2 ++
 apps/files_trashbin/lib/exceptions.php | 26 ++++++++++++++++++++++++++
 apps/files_trashbin/lib/trashbin.php   | 24 ++++++++++++++++++------
 3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php
index d30a601..d987593 100644
--- a/apps/files_trashbin/appinfo/app.php
+++ b/apps/files_trashbin/appinfo/app.php
@@ -2,6 +2,8 @@
 
 //OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'files_trashbin/lib/hooks.php';
 //OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'files_trashbin/lib/trash.php';
+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 0000000..23e5029
--- /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 at 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 7544980..19bcec7 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -122,10 +122,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`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
 			$result = $query->execute(array($filename, $timestamp, $location, $type, $mime, $user));
@@ -144,8 +152,6 @@ class Trashbin {
 			if ($user !== $owner) {
 				self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp, $type, $mime);
 			}
-		} else {
-			\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
 		}
 
 		$userTrashSize += $size;
@@ -841,13 +847,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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list