Refactor directory creation

This commit is contained in:
Niklas Keller
2018-01-11 17:00:27 +01:00
parent 19f6550e33
commit 69bc88daf1
3 changed files with 18 additions and 6 deletions

View File

@@ -47,8 +47,12 @@ class CertificateStore {
$chain = \array_slice($certificates, 1);
$path = $this->root . '/' . $commonName;
if (!(yield File\isdir($path)) && !(yield File\mkdir($path, 0644, true)) && !(yield File\isdir($path))) {
throw new FilesystemException("Couldn't create certificate directory: '{$path}'");
if (!yield File\isdir($path)) {
yield File\mkdir($path, 0644, true);
if (!yield File\isdir($path)) {
throw new FilesystemException("Couldn't create certificate directory: '{$path}'");
}
}
yield File\put($path . '/cert.pem', $certificates[0]);

View File

@@ -22,8 +22,12 @@ class ChallengeStore {
throw new ChallengeStoreException("Document root doesn't exist: '{$this->docroot}'");
}
if (!(yield File\isdir($path)) && !(yield File\mkdir($path, 0644, true)) && !(yield File\isdir($path))) {
throw new ChallengeStoreException("Couldn't create key directory: '{$path}'");
if (!yield File\isdir($path)) {
yield File\mkdir($path, 0644, true);
if (!yield File\isdir($path)) {
throw new ChallengeStoreException("Couldn't create key directory: '{$path}'");
}
}
if ($user && !$userInfo = \posix_getpwnam($user)) {

View File

@@ -43,8 +43,12 @@ class KeyStore {
try {
$dir = \dirname($file);
if (!(yield File\isdir($dir)) && !(yield File\mkdir($dir, 0644, true)) && !(yield File\isdir($dir))) {
throw new FilesystemException("Couldn't create key directory: '{$dir}'");
if (!yield File\isdir($dir)) {
yield File\mkdir($dir, 0644, true);
if (!yield File\isdir($dir)) {
throw new FilesystemException("Couldn't create key directory: '{$dir}'");
}
}
yield File\put($file, $key->toPem());