From 4526bc0ba6f23a2fae5f7372d9b7702736eb46f6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 30 Jun 2014 16:12:12 +0200 Subject: Handle StorageNotAvailableException in ajax/list.php --- apps/files/ajax/list.php | 64 ++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'apps/files') diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index bae3628402f..b94d00ed8f9 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -1,30 +1,40 @@ close(); - -// Load the files -$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; -$dir = \OC\Files\Filesystem::normalizePath($dir); -$dirInfo = \OC\Files\Filesystem::getFileInfo($dir); -if (!$dirInfo || !$dirInfo->getType() === 'dir') { - header("HTTP/1.0 404 Not Found"); - exit(); +try { + OCP\JSON::checkLoggedIn(); + \OC::$session->close(); + + // Load the files + $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; + $dir = \OC\Files\Filesystem::normalizePath($dir); + $dirInfo = \OC\Files\Filesystem::getFileInfo($dir); + if (!$dirInfo || !$dirInfo->getType() === 'dir') { + header("HTTP/1.0 404 Not Found"); + exit(); + } + + $data = array(); + $baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir='; + + $permissions = $dirInfo->getPermissions(); + + $sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name'; + $sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false; + + // make filelist + + $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); + $data['directory'] = $dir; + $data['files'] = \OCA\Files\Helper::formatFileInfos($files); + $data['permissions'] = $permissions; + + OCP\JSON::success(array('data' => $data)); +} catch (\OCP\Files\StorageNotAvailableException $e) { + $l = OC_L10N::get('files'); + OCP\JSON::error(array( + 'data' => array( + 'exception' => '\OCP\Files\StorageNotAvailableException', + 'message' => $l->t('Storage not available') + ) + )); } - -$data = array(); -$baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir='; - -$permissions = $dirInfo->getPermissions(); - -$sortAttribute = isset( $_GET['sort'] ) ? $_GET['sort'] : 'name'; -$sortDirection = isset( $_GET['sortdirection'] ) ? ($_GET['sortdirection'] === 'desc') : false; - -// make filelist -$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); - -$data['directory'] = $dir; -$data['files'] = \OCA\Files\Helper::formatFileInfos($files); -$data['permissions'] = $permissions; - -OCP\JSON::success(array('data' => $data)); -- cgit v1.2.3 From 30c240a145dd8c9e54b4cd64a78f1020e41a15f4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 30 Jun 2014 16:27:31 +0200 Subject: If loading a directory fails, navigate back to the previous directory --- apps/files/js/filelist.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'apps/files') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 0477a657035..ef28794b1b4 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -836,13 +836,18 @@ * @param {boolean} force set to true to force changing directory */ changeDirectory: function(targetDir, changeUrl, force) { + var self = this; var currentDir = this.getCurrentDirectory(); targetDir = targetDir || '/'; if (!force && currentDir === targetDir) { return; } this._setCurrentDir(targetDir, changeUrl); - this.reload(); + this.reload().then(function(success){ + if (!success) { + self.changeDirectory(currentDir, true); + } + }); }, linkTo: function(dir) { return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); @@ -902,7 +907,6 @@ * @brief Reloads the file list using ajax call */ reload: function() { - var self = this; this._selectedFiles = {}; this._selectionSummary.clear(); this.$el.find('.select-all').prop('checked', false); @@ -916,14 +920,10 @@ dir : this.getCurrentDirectory(), sort: this._sort, sortdirection: this._sortDirection - }, - error: function(result) { - self.reloadCallback(result); - }, - success: function(result) { - self.reloadCallback(result); } }); + var callBack = this.reloadCallback.bind(this); + return this._reloadCall.then(callBack, callBack); }, reloadCallback: function(result) { delete this._reloadCall; @@ -931,17 +931,17 @@ if (!result || result.status === 'error') { OC.Notification.show(result.data.message); - return; + return false; } if (result.status === 404) { // go back home this.changeDirectory('/'); - return; + return false; } // aborted ? if (result.status === 0){ - return; + return true; } // TODO: should rather return upload file size through @@ -953,6 +953,7 @@ } this.setFiles(result.data.files); + return true }, updateStorageStatistics: function(force) { -- cgit v1.2.3 From 8339618ead32bf21e76d65d0e0015cf0cd8adc1f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Jul 2014 14:58:17 +0200 Subject: More error catching in list.php --- apps/files/ajax/list.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'apps/files') diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index b94d00ed8f9..b4641343ed4 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -1,12 +1,14 @@ close(); +OCP\JSON::checkLoggedIn(); +\OC::$session->close(); +$l = OC_L10N::get('files'); + +// Load the files +$dir = isset($_GET['dir']) ? $_GET['dir'] : ''; +$dir = \OC\Files\Filesystem::normalizePath($dir); - // Load the files - $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; - $dir = \OC\Files\Filesystem::normalizePath($dir); +try { $dirInfo = \OC\Files\Filesystem::getFileInfo($dir); if (!$dirInfo || !$dirInfo->getType() === 'dir') { header("HTTP/1.0 404 Not Found"); @@ -30,11 +32,24 @@ try { OCP\JSON::success(array('data' => $data)); } catch (\OCP\Files\StorageNotAvailableException $e) { - $l = OC_L10N::get('files'); OCP\JSON::error(array( 'data' => array( 'exception' => '\OCP\Files\StorageNotAvailableException', 'message' => $l->t('Storage not available') ) )); +} catch (\OCP\Files\StorageInvalidException $e) { + OCP\JSON::error(array( + 'data' => array( + 'exception' => '\OCP\Files\StorageInvalidException', + 'message' => $l->t('Storage invalid') + ) + )); +} catch (\Exception $e) { + OCP\JSON::error(array( + 'data' => array( + 'exception' => '\Exception', + 'message' => $l->t('Unknown error') + ) + )); } -- cgit v1.2.3