throw exception if file is to large for trash bin

This commit is contained in:
Bjoern Schiessle 2014-07-14 17:03:36 +02:00
parent 6d76165873
commit 40fe1275de
3 changed files with 46 additions and 6 deletions

View File

@ -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();

View File

@ -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 {
}

View File

@ -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;