r112958 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112957‎ | r112958 | r112959 >
Date:19:14, 3 March 2012
Author:aaron
Status:ok
Tags:
Comment:
[FileBackend]
* Various documentation improvements.
* Moved a few protected FileBackendStoreShardListIterator functions down. Same with normalizeContainerPath().
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileBackendStore.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -6,7 +6,7 @@
77 */
88
99 /**
10 - * Class for a file system (FS) based file backend.
 10+ * @brief Class for a file system (FS) based file backend.
1111 *
1212 * All "containers" each map to a directory under the backend's base directory.
1313 * For backwards-compatibility, some container paths can be set to custom paths.
@@ -579,6 +579,10 @@
580580 }
581581 }
582582
 583+ /**
 584+ * @see Iterator::current()
 585+ * @return string|bool String or false
 586+ */
583587 public function current() {
584588 // Return only the relative path and normalize slashes to FileBackend-style
585589 // Make sure to use the realpath since the suffix is based upon that
@@ -586,10 +590,18 @@
587591 substr( realpath( $this->iter->current() ), $this->suffixStart ) );
588592 }
589593
 594+ /**
 595+ * @see Iterator::key()
 596+ * @return integer
 597+ */
590598 public function key() {
591599 return $this->pos;
592600 }
593601
 602+ /**
 603+ * @see Iterator::next()
 604+ * @return void
 605+ */
594606 public function next() {
595607 try {
596608 $this->iter->next();
@@ -599,6 +611,10 @@
600612 ++$this->pos;
601613 }
602614
 615+ /**
 616+ * @see Iterator::rewind()
 617+ * @return void
 618+ */
603619 public function rewind() {
604620 $this->pos = 0;
605621 try {
@@ -608,6 +624,10 @@
609625 }
610626 }
611627
 628+ /**
 629+ * @see Iterator::valid()
 630+ * @return bool
 631+ */
612632 public function valid() {
613633 return $this->iter && $this->iter->valid();
614634 }
Index: trunk/phase3/includes/filerepo/backend/FileBackendStore.php
@@ -997,6 +997,10 @@
998998 $this->params = $params;
999999 }
10001000
 1001+ /**
 1002+ * @see Iterator::current()
 1003+ * @return string|bool String or false
 1004+ */
10011005 public function current() {
10021006 if ( is_array( $this->iter ) ) {
10031007 return current( $this->iter );
@@ -1005,10 +1009,18 @@
10061010 }
10071011 }
10081012
 1013+ /**
 1014+ * @see Iterator::key()
 1015+ * @return integer
 1016+ */
10091017 public function key() {
10101018 return $this->pos;
10111019 }
10121020
 1021+ /**
 1022+ * @see Iterator::next()
 1023+ * @return void
 1024+ */
10131025 public function next() {
10141026 ++$this->pos;
10151027 if ( is_array( $this->iter ) ) {
@@ -1021,25 +1033,9 @@
10221034 }
10231035
10241036 /**
1025 - * If the iterator for this container shard is out of items,
1026 - * then move on to the next container that has items.
1027 - * If there are none, then it advances to the last container.
 1037+ * @see Iterator::rewind()
 1038+ * @return void
10281039 */
1029 - protected function nextShardIteratorIfNotValid() {
1030 - while ( !$this->valid() ) {
1031 - if ( ++$this->curShard >= count( $this->shardSuffixes ) ) {
1032 - break; // no more container shards
1033 - }
1034 - $this->setIteratorFromCurrentShard();
1035 - }
1036 - }
1037 -
1038 - protected function setIteratorFromCurrentShard() {
1039 - $suffix = $this->shardSuffixes[$this->curShard];
1040 - $this->iter = $this->backend->getFileListInternal(
1041 - "{$this->container}{$suffix}", $this->directory, $this->params );
1042 - }
1043 -
10441040 public function rewind() {
10451041 $this->pos = 0;
10461042 $this->curShard = 0;
@@ -1048,6 +1044,10 @@
10491045 $this->nextShardIteratorIfNotValid();
10501046 }
10511047
 1048+ /**
 1049+ * @see Iterator::valid()
 1050+ * @return bool
 1051+ */
10521052 public function valid() {
10531053 if ( $this->iter == null ) {
10541054 return false; // some failure?
@@ -1057,4 +1057,27 @@
10581058 return $this->iter->valid();
10591059 }
10601060 }
 1061+
 1062+ /**
 1063+ * If the list iterator for this container shard is out of items,
 1064+ * then move on to the next container that has items.
 1065+ * If there are none, then it advances to the last container.
 1066+ */
 1067+ protected function nextShardIteratorIfNotValid() {
 1068+ while ( !$this->valid() ) {
 1069+ if ( ++$this->curShard >= count( $this->shardSuffixes ) ) {
 1070+ break; // no more container shards
 1071+ }
 1072+ $this->setIteratorFromCurrentShard();
 1073+ }
 1074+ }
 1075+
 1076+ /**
 1077+ * Set the list iterator to that of the current container shard
 1078+ */
 1079+ protected function setIteratorFromCurrentShard() {
 1080+ $suffix = $this->shardSuffixes[$this->curShard];
 1081+ $this->iter = $this->backend->getFileListInternal(
 1082+ "{$this->container}{$suffix}", $this->directory, $this->params );
 1083+ }
10611084 }
Index: trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php
@@ -7,7 +7,7 @@
88 */
99
1010 /**
11 - * Class for an OpenStack Swift based file backend.
 11+ * @brief Class for an OpenStack Swift based file backend.
1212 *
1313 * This requires the SwiftCloudFiles MediaWiki extension, which includes
1414 * the php-cloudfiles library (https://github.com/rackspace/php-cloudfiles).
@@ -856,14 +856,26 @@
857857 }
858858 }
859859
 860+ /**
 861+ * @see Iterator::current()
 862+ * @return string|bool String or false
 863+ */
860864 public function current() {
861865 return substr( current( $this->bufferIter ), $this->suffixStart );
862866 }
863867
 868+ /**
 869+ * @see Iterator::key()
 870+ * @return integer
 871+ */
864872 public function key() {
865873 return $this->pos;
866874 }
867875
 876+ /**
 877+ * @see Iterator::next()
 878+ * @return void
 879+ */
868880 public function next() {
869881 // Advance to the next file in the page
870882 next( $this->bufferIter );
@@ -878,6 +890,10 @@
879891 }
880892 }
881893
 894+ /**
 895+ * @see Iterator::rewind()
 896+ * @return void
 897+ */
882898 public function rewind() {
883899 $this->pos = 0;
884900 $this->bufferAfter = null;
@@ -886,6 +902,10 @@
887903 );
888904 }
889905
 906+ /**
 907+ * @see Iterator::valid()
 908+ * @return bool
 909+ */
890910 public function valid() {
891911 return ( current( $this->bufferIter ) !== false ); // no paths can have this value
892912 }
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -14,7 +14,7 @@
1515 */
1616
1717 /**
18 - * Base class for all file backend classes (including multi-write backends).
 18+ * @brief Base class for all file backend classes (including multi-write backends).
1919 *
2020 * This class defines the methods as abstract that subclasses must implement.
2121 * Outside callers can assume that all backends will have these functions.
@@ -658,6 +658,31 @@
659659 }
660660
661661 /**
 662+ * Get the parent storage directory of a storage path.
 663+ * This returns a path like "mwstore://backend/container",
 664+ * "mwstore://backend/container/...", or null if there is no parent.
 665+ *
 666+ * @param $storagePath string
 667+ * @return string|null
 668+ */
 669+ final public static function parentStoragePath( $storagePath ) {
 670+ $storagePath = dirname( $storagePath );
 671+ list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
 672+ return ( $rel === null ) ? null : $storagePath;
 673+ }
 674+
 675+ /**
 676+ * Get the final extension from a storage or FS path
 677+ *
 678+ * @param $path string
 679+ * @return string
 680+ */
 681+ final public static function extensionFromPath( $path ) {
 682+ $i = strrpos( $path, '.' );
 683+ return strtolower( $i ? substr( $path, $i + 1 ) : '' );
 684+ }
 685+
 686+ /**
662687 * Validate and normalize a relative storage path.
663688 * Null is returned if the path involves directory traversal.
664689 * Traversal is insecure for FS backends and broken for others.
@@ -687,29 +712,4 @@
688713 }
689714 return $path;
690715 }
691 -
692 - /**
693 - * Get the parent storage directory of a storage path.
694 - * This returns a path like "mwstore://backend/container",
695 - * "mwstore://backend/container/...", or null if there is no parent.
696 - *
697 - * @param $storagePath string
698 - * @return string|null
699 - */
700 - final public static function parentStoragePath( $storagePath ) {
701 - $storagePath = dirname( $storagePath );
702 - list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
703 - return ( $rel === null ) ? null : $storagePath;
704 - }
705 -
706 - /**
707 - * Get the final extension from a storage or FS path
708 - *
709 - * @param $path string
710 - * @return string
711 - */
712 - final public static function extensionFromPath( $path ) {
713 - $i = strrpos( $path, '.' );
714 - return strtolower( $i ? substr( $path, $i + 1 ) : '' );
715 - }
716716 }
Index: trunk/phase3/includes/filerepo/backend/lockmanager/FSLockManager.php
@@ -38,6 +38,10 @@
3939 $this->lockDir = $config['lockDirectory'];
4040 }
4141
 42+ /**
 43+ * @see LockManager::doLock()
 44+ * @return Status
 45+ */
4246 protected function doLock( array $paths, $type ) {
4347 $status = Status::newGood();
4448
@@ -56,6 +60,10 @@
5761 return $status;
5862 }
5963
 64+ /**
 65+ * @see LockManager::doUnlock()
 66+ * @return Status
 67+ */
6068 protected function doUnlock( array $paths, $type ) {
6169 $status = Status::newGood();
6270
Index: trunk/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
@@ -68,6 +68,10 @@
6969 $this->session = wfBaseConvert( sha1( $this->session ), 16, 36, 31 );
7070 }
7171
 72+ /**
 73+ * @see LockManager::doLock()
 74+ * @return Status
 75+ */
7276 protected function doLock( array $paths, $type ) {
7377 $status = Status::newGood();
7478
@@ -117,6 +121,10 @@
118122 return $status;
119123 }
120124
 125+ /**
 126+ * @see LockManager::doUnlock()
 127+ * @return Status
 128+ */
121129 protected function doUnlock( array $paths, $type ) {
122130 $status = Status::newGood();
123131
Index: trunk/phase3/includes/filerepo/backend/lockmanager/LockManager.php
@@ -11,7 +11,7 @@
1212 */
1313
1414 /**
15 - * Class for handling resource locking.
 15+ * @brief Class for handling resource locking.
1616 *
1717 * Locks on resource keys can either be shared or exclusive.
1818 *
@@ -178,10 +178,18 @@
179179 * @since 1.19
180180 */
181181 class NullLockManager extends LockManager {
 182+ /**
 183+ * @see LockManager::doLock()
 184+ * @return Status
 185+ */
182186 protected function doLock( array $paths, $type ) {
183187 return Status::newGood();
184188 }
185189
 190+ /**
 191+ * @see LockManager::doUnlock()
 192+ * @return Status
 193+ */
186194 protected function doUnlock( array $paths, $type ) {
187195 return Status::newGood();
188196 }

Status & tagging log