From: Aaron Date: Thu, 16 Aug 2012 00:24:20 +0000 (-0700) Subject: [FileBackend] Added resyncFiles() function to multiwrite backend. X-Git-Tag: 1.31.0-rc.0~22718 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=c51a9a288b6dd5c0023a77f324c04707b23501c6;p=lhc%2Fweb%2Fwiklou.git [FileBackend] Added resyncFiles() function to multiwrite backend. * Also fixed the the SHA1 function calls in consistencyCheck(). Change-Id: I29758ff79102929aa0ffb756526d7918bf74ca39 --- diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php index e9136d5af8..a055e088a7 100644 --- a/includes/filebackend/FileBackendMultiWrite.php +++ b/includes/filebackend/FileBackendMultiWrite.php @@ -167,7 +167,7 @@ class FileBackendMultiWrite extends FileBackend { /** * Check that a set of files are consistent across all internal backends * - * @param $paths Array + * @param $paths Array List of storage paths * @return Status */ public function consistencyCheck( array $paths ) { @@ -183,7 +183,7 @@ class FileBackendMultiWrite extends FileBackend { // Stat the file on the 'master' backend $mStat = $mBackend->getFileStat( $mParams ); if ( $this->syncChecks & self::CHECK_SHA1 ) { - $mSha1 = $mBackend->getFileSha1( $mParams ); + $mSha1 = $mBackend->getFileSha1Base36( $mParams ); } else { $mSha1 = false; } @@ -215,7 +215,7 @@ class FileBackendMultiWrite extends FileBackend { } } if ( $this->syncChecks & self::CHECK_SHA1 ) { - if ( $cBackend->getFileSha1( $cParams ) !== $mSha1 ) { // wrong SHA1 + if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1 $status->fatal( 'backend-fail-synced', $path ); continue; } @@ -234,6 +234,44 @@ class FileBackendMultiWrite extends FileBackend { return $status; } + /** + * Check that a set of files are consistent across all internal backends + * and re-synchronize those files againt the "multi master" if needed. + * + * @param $paths Array List of storage paths + * @return Status + */ + public function resyncFiles( array $paths ) { + $status = Status::newGood(); + + $mBackend = $this->backends[$this->masterIndex]; + foreach ( $paths as $path ) { + $mPath = $this->substPaths( $path, $mBackend ); + $mSha1 = $mBackend->getFileSha1Base36( array( 'src' => $mPath ) ); + $mExist = $mBackend->fileExists( array( 'src' => $mPath ) ); + // Check of all clone backends agree with the master... + foreach ( $this->backends as $index => $cBackend ) { + if ( $index === $this->masterIndex ) { + continue; // master + } + $cPath = $this->substPaths( $path, $cBackend ); + $cSha1 = $cBackend->getFileSha1Base36( array( 'src' => $cPath ) ); + if ( $mSha1 === $cSha1 ) { + // already synced; nothing to do + } elseif ( $mSha1 ) { // file is in master + $fsFile = $mBackend->getLocalReference( array( 'src' => $mPath ) ); + $status->merge( $cBackend->quickStore( + array( 'src' => $fsFile->getPath(), 'dst' => $cPath ) + ) ); + } elseif ( $mExist === false ) { // file is not in master + $status->merge( $cBackend->quickDelete( array( 'src' => $cPath ) ) ); + } + } + } + + return $status; + } + /** * Get a list of file storage paths to read or write for a list of operations *