Skip to content

Handle possible race condition with mkdir #71

@arogachev

Description

@arogachev

https://github.com/kalessil/phpinspectionsea/blob/master/docs/probable-bugs.md#mkdir-race-condition

Extracted from comment:

if (!is_dir($directory)) {
set_error_handler(static function (int $errorNumber, string $errorString) use ($directory): bool {
// Handle race condition.
// See https://github.com/kalessil/phpinspectionsea/blob/master/docs/probable-bugs.md#mkdir-race-condition
if (!is_dir($directory)) {
throw new RuntimeException(
sprintf('Failed to create directory "%s". ', $directory) . $errorString,
$errorNumber
);
}
return true;
});
mkdir($directory, 0775, true);
restore_error_handler();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions