From: Aaron Schulz Date: Tue, 1 Oct 2013 20:53:13 +0000 (-0700) Subject: Make sure LocalFile::lock() works for brand new uploads X-Git-Tag: 1.31.0-rc.0~18631 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=2cd16b8a4ed80187594e2c6c2d82161205efc526;p=lhc%2Fweb%2Fwiklou.git Make sure LocalFile::lock() works for brand new uploads bug: 54736 Change-Id: I10f950939d34ff5917d168ef1d905c86e2cfc075 --- diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index d6dc150a58..9653db94cc 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1764,6 +1764,16 @@ class LocalFile extends File { $this->lockedOwnTrx = true; } $this->locked++; + // Bug 54736: use simple lock to handle when the file does not exist. + // SELECT FOR UPDATE only locks records not the gaps where there are none. + $cache = wfGetMainCache(); + $key = $this->getCacheKey(); + if ( !$cache->lock( $key, 60 ) ) { + throw new MWException( "Could not acquire lock for '{$this->getName()}.'" ); + } + $dbw->onTransactionIdle( function() use ( $cache, $key ) { + $cache->delete( $key ); // release on commit + } ); } return $dbw->selectField( 'image', '1',