Skip to content

Commit

Permalink
Fixed error that could occur when acquiring file lock
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Oct 16, 2018
1 parent 8181490 commit dd21625
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- Craft.MatrixInput now fires an `afterInit` event after initialization. ([#3375](https://github.com/craftcms/cms/pull/3375))
- Craft.MatrixInput now fires an `blockAdded` event after adding a new block. ([#3375](https://github.com/craftcms/cms/pull/3375))

### Fixed
- Fixed an error that could occur when acquiring a lock for a file path, if the `mutex` component was swapped out with `yii\mutex\MysqlMutex`.

## 3.0.27.1 - 2018-10-12

### Fixed
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ public static function writeToFile(string $file, string $contents, array $option
}

if ($lock) {
Craft::$app->getMutex()->acquire($file);
$mutex = Craft::$app->getMutex();
$lockName = md5($file);
$mutex->acquire($lockName);
} else {
$lockName = $mutex = null;
}

$flags = 0;
Expand All @@ -350,7 +354,7 @@ public static function writeToFile(string $file, string $contents, array $option
}

if ($lock) {
Craft::$app->getMutex()->release($file);
$mutex->release($lockName);
}
}

Expand Down

0 comments on commit dd21625

Please # to comment.