Make sure LocalFile::lock() works for brand new uploads
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 1 Oct 2013 20:53:13 +0000 (13:53 -0700)
committerTim Starling <tstarling@wikimedia.org>
Tue, 1 Oct 2013 23:53:11 +0000 (23:53 +0000)
bug: 54736
Change-Id: I10f950939d34ff5917d168ef1d905c86e2cfc075

includes/filerepo/file/LocalFile.php

index d6dc150..9653db9 100644 (file)
@@ -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',