Skip to content

Commit

Permalink
fix: Only throw exception when creating directory really failed in Ha…
Browse files Browse the repository at this point in the history
…ndleFailureTrait (#2341)

When multiple processes try to create a directory at the same time `mkdir` is going to fail and return false. This should not warrant an exception.

This change ensures the directory exists - and only throws when it does not.
  • Loading branch information
gedimin45 authored and dwsupplee committed Oct 9, 2019
1 parent e06e57e commit 65d3f6d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Core/src/Batch/HandleFailureTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ private function initFailureFile()
sys_get_temp_dir()
);
}
if (! is_dir($this->baseDir)) {
if (@mkdir($this->baseDir, 0700, true) === false) {
throw new \RuntimeException(
sprintf(
'Couuld not create a directory: %s',
$this->baseDir
)
);
}

if (!is_dir($this->baseDir) && !@mkdir($this->baseDir, 0700, true) && !is_dir($this->baseDir)) {
throw new \RuntimeException(
sprintf(
'Could not create a directory: %s',
$this->baseDir
)
);
}

// Use getmypid for simplicity.
$this->failureFile = sprintf(
'%s/failed-items-%d',
Expand Down

0 comments on commit 65d3f6d

Please sign in to comment.