From 40fe1275de1dcdb3f17027ceeaef19164956e146 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 14 Jul 2014 17:03:36 +0200 Subject: [PATCH] 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(-) create mode 100644 apps/files_trashbin/lib/exceptions.php diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index 383115b8e6..718c2f45a3 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -1,6 +1,8 @@ . + * + */ + +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 522f7d4b7e..ee3969323c 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;