Skip to content

Commit

Permalink
Ignore deletion exception on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 8, 2024
1 parent 70df517 commit 9f06c5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/FileMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ public function acquire(?Cancellation $cancellation = null): Lock
*/
private function release(File $file): void
{
$file->close();

try {
$this->filesystem->deleteFile($this->fileName); // Delete file while holding the lock.
$file->close();
$this->filesystem->deleteFile($this->fileName);
} catch (FilesystemException $exception) {
if (IS_WINDOWS) {
return; // Windows will fail to delete the file if another handle is open.
}

throw new SyncException(
'Failed to unlock the mutex file: ' . $this->fileName,
previous: $exception,
Expand Down

0 comments on commit 9f06c5f

Please sign in to comment.