From 69bc88daf1ad698b8382dd2599a8bcfad1703694 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Thu, 11 Jan 2018 17:00:27 +0100 Subject: [PATCH] Refactor directory creation --- src/Stores/CertificateStore.php | 8 ++++++-- src/Stores/ChallengeStore.php | 8 ++++++-- src/Stores/KeyStore.php | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Stores/CertificateStore.php b/src/Stores/CertificateStore.php index 6bd32a4..48d72cb 100644 --- a/src/Stores/CertificateStore.php +++ b/src/Stores/CertificateStore.php @@ -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]); diff --git a/src/Stores/ChallengeStore.php b/src/Stores/ChallengeStore.php index 766891b..ec1a5ec 100644 --- a/src/Stores/ChallengeStore.php +++ b/src/Stores/ChallengeStore.php @@ -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)) { diff --git a/src/Stores/KeyStore.php b/src/Stores/KeyStore.php index e66ed5d..859283f 100644 --- a/src/Stores/KeyStore.php +++ b/src/Stores/KeyStore.php @@ -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());