X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FsyncFileBackend.php;h=2dcf7571942b33e94f8f6a0313a689f445aa3695;hb=96c5ca47255fca62c3d8fec95aa411699650ce0a;hp=0d5c9deec66a652a7d40d9d5be651a17f437a9f9;hpb=4024de4bd87c62760896a427b3f68fe165fe4960;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/syncFileBackend.php b/maintenance/syncFileBackend.php index 0d5c9deec6..2dcf757194 100644 --- a/maintenance/syncFileBackend.php +++ b/maintenance/syncFileBackend.php @@ -39,12 +39,11 @@ class SyncFileBackend extends Maintenance { $src = FileBackendGroup::singleton()->get( $this->getOption( 'src' ) ); $dst = FileBackendGroup::singleton()->get( $this->getOption( 'dst' ) ); - $posFile = $this->getOption( 'posdir' ) - ? $this->getOption( 'posdir' ) . '/' . wfWikiID() - : false; + $posDir = $this->getOption( 'posdir' ); + $posFile = $posDir ? $posDir . '/' . wfWikiID() : false; $start = $this->getOption( 'start', 0 ); - if ( !$start && $posFile ) { + if ( !$start && $posFile && is_dir( $posDir ) ) { $start = is_file( $posFile ) ? (int)trim( file_get_contents( $posFile ) ) : 0; @@ -66,8 +65,11 @@ class SyncFileBackend extends Maintenance { // Update the sync position file if ( $startFromPosFile && $lastOKPos >= $start ) { // successfully advanced - file_put_contents( $posFile, $lastOKPos, LOCK_EX ); - $this->output( "Updated journal position file.\n" ); + if ( file_put_contents( $posFile, $lastOKPos, LOCK_EX ) !== false ) { + $this->output( "Updated journal position file.\n" ); + } else { + $this->output( "Could not update journal position file.\n" ); + } } if ( $lastOKPos === false ) { @@ -127,7 +129,7 @@ class SyncFileBackend extends Maintenance { if ( $status->isOK() ) { $lastOKPos = max( $lastOKPos, $lastPosInBatch ); } else { - $this->output( print_r( $status->getErrorsArray(), true ) ); + $this->error( print_r( $status->getErrorsArray(), true ) ); break; // no gaps; everything up to $lastPos must be OK } @@ -183,7 +185,8 @@ class SyncFileBackend extends Maintenance { } $fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed // Note: prepare() is usually fast for key/value backends - $status->merge( $dst->prepare( array( 'dir' => dirname( $dPath ) ) ) ); + $status->merge( $dst->prepare( array( + 'dir' => dirname( $dPath ), 'bypassReadOnly' => 1 ) ) ); if ( !$status->isOK() ) { return $status; } @@ -198,10 +201,12 @@ class SyncFileBackend extends Maintenance { } } - $status->merge( $dst->doOperations( $ops, - array( 'nonLocking' => 1, 'nonJournaled' => 1 ) ) ); + $t_start = microtime( true ); + $status->merge( $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) ) ); + $ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 ); if ( $status->isOK() && $this->getOption( 'verbose' ) ) { - $this->output( "Synchronized these file(s):\n" . implode( "\n", $dPaths ) . "\n" ); + $this->output( "Synchronized these file(s) [{$ellapsed_ms}ms]:\n" . + implode( "\n", $dPaths ) . "\n" ); } return $status;