Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/68940
Change subject: filebackend: throw exceptions during file iteration.
......................................................................
filebackend: throw exceptions during file iteration.
* This lets calling code be far more robust rather than just
silently ignoring entries due to some temporary problem.
Change-Id: I3ce2ae34f6cff5e40a80b8da5688503a387ce2a6
---
M includes/AutoLoader.php
M includes/filebackend/FSFileBackend.php
M includes/filebackend/FileBackend.php
M includes/filebackend/SwiftFileBackend.php
4 files changed, 28 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/40/68940/1
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 02c92df..38b27e6 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -551,6 +551,7 @@
# includes/filebackend
'FileBackendGroup' => 'includes/filebackend/FileBackendGroup.php',
'FileBackend' => 'includes/filebackend/FileBackend.php',
+ 'FileBackendError' => 'includes/filebackend/FileBackend.php',
'FileBackendStore' => 'includes/filebackend/FileBackendStore.php',
'FileBackendStoreShardListIterator' =>
'includes/filebackend/FileBackendStore.php',
'FileBackendStoreShardDirIterator' =>
'includes/filebackend/FileBackendStore.php',
diff --git a/includes/filebackend/FSFileBackend.php
b/includes/filebackend/FSFileBackend.php
index dfc5192..6d64216 100644
--- a/includes/filebackend/FSFileBackend.php
+++ b/includes/filebackend/FSFileBackend.php
@@ -854,8 +854,8 @@
try {
$this->iter->next();
$this->filterViaNext();
- } catch ( UnexpectedValueException $e ) {
- $this->iter = null;
+ } catch ( UnexpectedValueException $e ) { // bad permissions?
deleted?
+ throw new FileBackendError( "File iterator gave
UnexpectedValueException." );
}
++$this->pos;
}
@@ -869,8 +869,8 @@
try {
$this->iter->rewind();
$this->filterViaNext();
- } catch ( UnexpectedValueException $e ) {
- $this->iter = null;
+ } catch ( UnexpectedValueException $e ) { // bad permissions?
deleted?
+ throw new FileBackendError( "File iterator gave
UnexpectedValueException." );
}
}
diff --git a/includes/filebackend/FileBackend.php
b/includes/filebackend/FileBackend.php
index 29af88d..9b4760a 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -1061,6 +1061,8 @@
*
* Storage backends with eventual consistency might return stale data.
*
+ * Failures during iteration can result in FileBackendError exceptions
(since 1.22).
+ *
* @param array $params
* $params include:
* - dir : storage directory
@@ -1075,6 +1077,8 @@
* directories that are immediately under the given directory.
*
* Storage backends with eventual consistency might return stale data.
+ *
+ * Failures during iteration can result in FileBackendError exceptions
(since 1.22).
*
* @param array $params
* $params include:
@@ -1096,6 +1100,8 @@
*
* Storage backends with eventual consistency might return stale data.
*
+ * Failures during iteration can result in FileBackendError exceptions
(since 1.22).
+ *
* @param array $params
* $params include:
* - dir : storage directory
@@ -1110,6 +1116,8 @@
* files that are immediately under the given directory.
*
* Storage backends with eventual consistency might return stale data.
+ *
+ * Failures during iteration can result in FileBackendError exceptions
(since 1.22).
*
* @param array $params
* $params include:
@@ -1379,3 +1387,9 @@
return $path;
}
}
+
+/**
+ * @ingroup FileBackend
+ * @since 1.22
+ */
+class FileBackendError extends MWException {}
diff --git a/includes/filebackend/SwiftFileBackend.php
b/includes/filebackend/SwiftFileBackend.php
index a57bf59..f3aa145 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -926,6 +926,7 @@
* @param integer $limit Max number of items to list
* @param array $params Parameters for getDirectoryList()
* @return Array List of resolved paths of directories directly under
$dir
+ * @throws FileBackendError
*/
public function getDirListPageInternal( $fullCont, $dir, &$after,
$limit, array $params ) {
$dirs = array();
@@ -933,7 +934,7 @@
return $dirs; // nothing more
}
- wfProfileIn( __METHOD__ . '-' . $this->name );
+ $section = new ProfileSection( __METHOD__ . '-' . $this->name );
try {
$container = $this->getContainer( $fullCont );
$prefix = ( $dir == '' ) ? null : "{$dir}/";
@@ -981,8 +982,8 @@
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, null, __METHOD__,
array( 'cont' => $fullCont, 'dir' => $dir ) );
+ throw new FileBackendError( "Got " . get_class( $e ) .
" exception." );
}
- wfProfileOut( __METHOD__ . '-' . $this->name );
return $dirs;
}
@@ -1000,6 +1001,7 @@
* @param integer $limit Max number of items to list
* @param array $params Parameters for getDirectoryList()
* @return Array List of resolved paths of files under $dir
+ * @throws FileBackendError
*/
public function getFileListPageInternal( $fullCont, $dir, &$after,
$limit, array $params ) {
$files = array();
@@ -1007,7 +1009,7 @@
return $files; // nothing more
}
- wfProfileIn( __METHOD__ . '-' . $this->name );
+ $section = new ProfileSection( __METHOD__ . '-' . $this->name );
try {
$container = $this->getContainer( $fullCont );
$prefix = ( $dir == '' ) ? null : "{$dir}/";
@@ -1048,8 +1050,8 @@
} catch ( CloudFilesException $e ) { // some other exception?
$this->handleException( $e, null, __METHOD__,
array( 'cont' => $fullCont, 'dir' => $dir ) );
+ throw new FileBackendError( "Got " . get_class( $e ) .
" exception." );
}
- wfProfileOut( __METHOD__ . '-' . $this->name );
return $files;
}
@@ -1653,7 +1655,7 @@
* @param string $after|null
* @param integer $limit
* @param array $params
- * @return Traversable|Array|null Returns null on failure
+ * @return Traversable|Array
*/
abstract protected function pageFromList( $container, $dir, &$after,
$limit, array $params );
}
@@ -1672,7 +1674,7 @@
/**
* @see SwiftFileBackendList::pageFromList()
- * @return Array|null
+ * @return Array
*/
protected function pageFromList( $container, $dir, &$after, $limit,
array $params ) {
return $this->backend->getDirListPageInternal( $container,
$dir, $after, $limit, $params );
@@ -1693,7 +1695,7 @@
/**
* @see SwiftFileBackendList::pageFromList()
- * @return Array|null
+ * @return Array
*/
protected function pageFromList( $container, $dir, &$after, $limit,
array $params ) {
return $this->backend->getFileListPageInternal( $container,
$dir, $after, $limit, $params );
--
To view, visit https://gerrit.wikimedia.org/r/68940
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ce2ae34f6cff5e40a80b8da5688503a387ce2a6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits