Skip to content

Handle possible race condition with mkdir #71

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();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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