[Pkg-owncloud-commits] [owncloud] 283/457: Catch exceptions in files ajax calls

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:06:24 UTC 2015


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

taffit pushed a commit to branch stable8
in repository owncloud.

commit 263bb46ff892c0a7de7852ce0ab9b9c1d2381054
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Jun 3 14:31:58 2015 +0200

    Catch exceptions in files ajax calls
---
 apps/files/ajax/delete.php    | 13 +++++++++----
 apps/files/ajax/newfile.php   | 19 +++++++++++++++----
 apps/files/ajax/newfolder.php | 27 +++++++++++++++++++--------
 apps/files/ajax/rename.php    | 21 ++++++++++++++++-----
 4 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php
index 9d4f0b0..dcd05d8 100644
--- a/apps/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -54,10 +54,15 @@ $success = true;
 
 //Now delete
 foreach ($files as $file) {
-	if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) &&
-		!(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) &&
-			\OC\Files\Filesystem::unlink($dir . '/' . $file))
-	) {
+	try {
+		if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) &&
+			!(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) &&
+				\OC\Files\Filesystem::unlink($dir . '/' . $file))
+		) {
+			$filesWithError .= $file . "\n";
+			$success = false;
+		}
+	} catch (\Exception $e) {
 		$filesWithError .= $file . "\n";
 		$success = false;
 	}
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
index b4e1e50..6dd3e3e 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -78,10 +78,21 @@ $templateManager = OC_Helper::getFileTemplateManager();
 $mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
 $content = $templateManager->getTemplate($mimeType);
 
-if($content) {
-	$success = \OC\Files\Filesystem::file_put_contents($target, $content);
-} else {
-	$success = \OC\Files\Filesystem::touch($target);
+try {
+	if($content) {
+		$success = \OC\Files\Filesystem::file_put_contents($target, $content);
+	} else {
+		$success = \OC\Files\Filesystem::touch($target);
+	}
+} catch (\Exception $e) {
+	$result = [
+		'success' => false,
+		'data' => [
+			'message' => $e->getMessage()
+		]
+	];
+	OCP\JSON::error($result);
+	exit();
 }
 
 if($success) {
diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
index 90bc9ec..b15457e 100644
--- a/apps/files/ajax/newfolder.php
+++ b/apps/files/ajax/newfolder.php
@@ -74,15 +74,26 @@ if (\OC\Files\Filesystem::file_exists($target)) {
 	exit();
 }
 
-if(\OC\Files\Filesystem::mkdir($target)) {
-	if ( $dir !== '/') {
-		$path = $dir.'/'.$folderName;
-	} else {
-		$path = '/'.$folderName;
+try {
+	if(\OC\Files\Filesystem::mkdir($target)) {
+		if ( $dir !== '/') {
+			$path = $dir.'/'.$folderName;
+		} else {
+			$path = '/'.$folderName;
+		}
+		$meta = \OC\Files\Filesystem::getFileInfo($path);
+		$meta['type'] = 'dir'; // missing ?!
+		OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
+		exit();
 	}
-	$meta = \OC\Files\Filesystem::getFileInfo($path);
-	$meta['type'] = 'dir'; // missing ?!
-	OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
+} catch (\Exception $e) {
+	$result = [
+		'success' => false,
+		'data' => [
+			'message' => $e->getMessage()
+		]
+	];
+	OCP\JSON::error($result);
 	exit();
 }
 
diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php
index 576902e..edb6dd7 100644
--- a/apps/files/ajax/rename.php
+++ b/apps/files/ajax/rename.php
@@ -29,15 +29,26 @@ OCP\JSON::checkLoggedIn();
 OCP\JSON::callCheck();
 \OC::$server->getSession()->close();
 
+$l10n = \OC::$server->getL10N('files');
+
 $files = new \OCA\Files\App(
 	\OC\Files\Filesystem::getView(),
 	\OC::$server->getL10N('files')
 );
-$result = $files->rename(
-	isset($_GET['dir']) ? (string)$_GET['dir'] : '',
-	isset($_GET['file']) ? (string)$_GET['file'] : '',
-	isset($_GET['newname']) ? (string)$_GET['newname'] : ''
-);
+try {
+	$result = $files->rename(
+		isset($_GET['dir']) ? (string)$_GET['dir'] : '',
+		isset($_GET['file']) ? (string)$_GET['file'] : '',
+		isset($_GET['newname']) ? (string)$_GET['newname'] : ''
+	);
+} catch (\Exception $e) {
+	$result = [
+		'success' => false,
+		'data' => [
+			'message' => $e->getMessage()
+		]
+	];
+}
 
 if($result['success'] === true){
 	OCP\JSON::success(['data' => $result['data']]);

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