r102483 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102482‎ | r102483 | r102484 >
Date:02:44, 9 November 2011
Author:tstarling
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/ExtensionDistributor (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ExtensionDistributor/cron.php (added) (history)
  • /branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.conf.sample (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.conf.sample
@@ -1,4 +1,4 @@
22 <?php
33
44 $wgExtDistWorkingCopy = '/path/to/mw-working-copy';
5 -
 5+$wgExtDistLockFile = '/path/to/lock-file';
Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/cron.php
@@ -0,0 +1,52 @@
 2+<?php
 3+
 4+/**
 5+ * Script to be run from cron, to update the svn working copies (especially new extensions)
 6+ */
 7+
 8+if ( php_sapi_name() !== 'cli' ) {
 9+ echo "This script can only be run from the command line\n";
 10+ exit( 1 );
 11+}
 12+
 13+$wgExtDistWorkingCopy = false;
 14+$wgExtDistLockFile = false;
 15+$confFile = dirname( __FILE__ ) . '/svn-invoker.conf';
 16+if ( !file_exists( $confFile ) ) {
 17+ echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n";
 18+ exit( 1 );
 19+}
 20+require( $confFile );
 21+
 22+cronExecute();
 23+
 24+function cronExecute() {
 25+ global $wgExtDistLockFile;
 26+ if ( $wgExtDistLockFile ) {
 27+ $lockFile = fopen( $wgExtDistLockFile, 'r+' );
 28+ if ( !$lockFile ) {
 29+ echo "Error opening lock file\n";
 30+ exit( 1 );
 31+ }
 32+ if ( !flock( $lockFile, LOCK_EX | LOCK_NB ) ) {
 33+ echo "Error obtaining lock\n";
 34+ exit( 1 );
 35+ }
 36+ }
 37+
 38+ // Update the files
 39+ svnUpdate( "$wgExtDistWorkingCopy/trunk" );
 40+ for ( glob( "$wgExtDistWorkingCopy/branches/*", GLOB_ONLYDIR ) as $branch ) {
 41+ svnUpdate( $branch );
 42+ }
 43+}
 44+
 45+function svnUpdate( $path ) {
 46+ $cmd = "svn up --non-interactive " . escapeshellarg( $path );
 47+ $retval = 1;
 48+ system( $cmd, $retval );
 49+ if ( $retval ) {
 50+ echo "Error executing command: $cmd\n";
 51+ exit( 1 );
 52+ }
 53+}
Property changes on: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/cron.php
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: branches/wmf/1.18wmf1/extensions/ExtensionDistributor/svn-invoker.php
@@ -9,6 +9,8 @@
1010 exit( 1 );
1111 }
1212
 13+$wgExtDistWorkingCopy = false;
 14+$wgExtDistLockFile = false;
1315 $confFile = dirname( __FILE__ ) . '/svn-invoker.conf';
1416 if ( !file_exists( $confFile ) ) {
1517 echo "Error: please create svn-invoker.conf based on svn-invoker.conf.sample\n";
@@ -39,7 +41,7 @@
4042 }
4143
4244 function svnExecute() {
43 - global $wgExtDistWorkingCopy;
 45+ global $wgExtDistWorkingCopy, $wgExtDistLockFile;
4446
4547 $encCommand = '';
4648 $done = false;
@@ -57,6 +59,30 @@
5860 return;
5961 }
6062
 63+ if ( $wgExtDistLockFile ) {
 64+ $lockFile = fopen( $wgExtDistLockFile, 'r+' );
 65+ if ( !$lockFile ) {
 66+ svnError( 'extdist-remote-error', "Unable to open lock file." );
 67+ return;
 68+ }
 69+ $timeout = 20;
 70+ for ( $i = 0; $i < $timeout; $i++ ) {
 71+ $wouldBlock = false;
 72+ if ( flock( $lockFile, LOCK_EX | LOCK_NB ) ) {
 73+ break;
 74+ }
 75+ if ( !$wouldBlock ) {
 76+ svnError( 'extdist-remote-error', "Error attempting to obtain lock." );
 77+ return;
 78+ }
 79+ sleep( 1 );
 80+ }
 81+ if ( $i == $timeout ) {
 82+ svnError( 'extdist-remote-error', "Lock wait timeout." );
 83+ return;
 84+ }
 85+ }
 86+
6187 $command = json_decode( $encCommand );
6288 if ( !isset( $command->version ) || !isset( $command->extension ) ) {
6389 svnError( 'extdist-remote-error', "Missing version or extension parameter." );
Property changes on: branches/wmf/1.18wmf1/extensions/ExtensionDistributor
___________________________________________________________________
Modified: svn:mergeinfo
6490 Merged /trunk/extensions/ExtensionDistributor:r102482

Follow-up revisions

RevisionCommit summaryAuthorDate
r102499Fixed a couple of obvious errors from r102483 which came up during testingtstarling09:40, 9 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102482Added an external locking layer around Subversion access to the repository. I...tstarling02:40, 9 November 2011

Status & tagging log