60 parent::__construct( $config );
62 $this->lockDir = $config[
'lockDirectory'];
63 $this->isWindows = ( strtoupper( substr( PHP_OS, 0, 3 ) ) ===
'WIN' );
76 foreach ( $paths as
$path ) {
79 $lockedPaths[] =
$path;
100 foreach ( $paths as
$path ) {
117 if ( isset( $this->locksHeld[
$path][
$type] ) ) {
119 } elseif ( isset( $this->locksHeld[
$path][self::LOCK_EX] ) ) {
122 if ( isset( $this->handles[
$path] ) ) {
123 $handle = $this->handles[
$path];
125 Wikimedia\suppressWarnings();
126 $handle = fopen( $this->
getLockPath( $path ),
'a+' );
127 if ( !$handle && !is_dir( $this->lockDir ) ) {
129 if ( mkdir( $this->lockDir, 0777,
true ) ) {
130 $handle = fopen( $this->
getLockPath( $path ),
'a+' );
132 $this->logger->error(
"Cannot create directory '{$this->lockDir}'." );
135 Wikimedia\restoreWarnings();
140 if ( flock( $handle, $lock | LOCK_NB ) ) {
143 $this->handles[
$path] = $handle;
146 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
166 if ( !isset( $this->locksHeld[
$path] ) ) {
168 } elseif ( !isset( $this->locksHeld[
$path][
$type] ) ) {
171 $handlesToClose = [];
176 if ( $this->locksHeld[
$path] === [] ) {
177 unset( $this->locksHeld[
$path] );
178 if ( isset( $this->handles[
$path] ) ) {
179 $handlesToClose[] = $this->handles[
$path];
180 unset( $this->handles[
$path] );
185 if ( $this->isWindows ) {
208 foreach ( $handlesToClose as $handle ) {
209 if ( !flock( $handle, LOCK_UN ) ) {
210 $status->fatal(
'lockmanager-fail-releaselock',
$path );
212 if ( !fclose( $handle ) ) {
213 $status->warning(
'lockmanager-fail-closelock',
$path );
226 if ( !isset( $this->locksHeld[
$path] ) ) {
227 # No locks are held for the lock file anymore
229 $status->warning(
'lockmanager-fail-deletelock',
$path );
231 unset( $this->handles[
$path] );
243 return "{$this->lockDir}/{$this->sha1Base36Absolute( $path )}.lock";
250 while ( count( $this->locksHeld ) ) {
251 foreach ( $this->locksHeld as
$path => $locks ) {