From 10842e96ec5c011faa41dcbb9a12ea2bf2da7414 Mon Sep 17 00:00:00 2001 From: Olavo Belloc Date: Mon, 4 Aug 2025 11:58:18 +0200 Subject: [PATCH 1/2] Fix race-condition with multiple workers When running ssg with multiple workers, different forked processes might check for an existing folder and attempt to create it "simultaneously", which will cause makeDirectory to fail (folder already exists) and ssg to abort. The fix uses 'force' to ignore errors on makeDirectory(). If it fails with errors other than 'folder already exists', then the following put() should also fail, meaning, it won't go unnoticed. --- src/Page.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Page.php b/src/Page.php index 1145d1f..b0b4b8d 100644 --- a/src/Page.php +++ b/src/Page.php @@ -63,9 +63,7 @@ protected function write($request) $html = $response->getContent(); - if (! $this->files->exists($this->directory())) { - $this->files->makeDirectory($this->directory(), 0755, true); - } + $this->files->makeDirectory($this->directory(), 0755, true, true); $this->files->put($this->path(), $html); From f0e21e45bb428cfee6c241c14fc6b55c03634e8e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 22 Sep 2025 12:04:37 +0100 Subject: [PATCH 2/2] use named arguments to make it clearer --- src/Page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Page.php b/src/Page.php index b0b4b8d..19df2de 100644 --- a/src/Page.php +++ b/src/Page.php @@ -63,7 +63,7 @@ protected function write($request) $html = $response->getContent(); - $this->files->makeDirectory($this->directory(), 0755, true, true); + $this->files->makeDirectory($this->directory(), recursive: true, force: true); $this->files->put($this->path(), $html);