From 2cd16b8a4ed80187594e2c6c2d82161205efc526 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 1 Oct 2013 13:53:13 -0700 Subject: [PATCH] Make sure LocalFile::lock() works for brand new uploads bug: 54736 Change-Id: I10f950939d34ff5917d168ef1d905c86e2cfc075 --- includes/filerepo/file/LocalFile.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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', -- 2.20.1