From 18e28a2a9fe5a9c7bedc0751ccfbf40f9c1800e0 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 2 Oct 2011 20:46:33 +0200 Subject: [PATCH] Make sure .composer dir is created before writing in it --- src/Composer/Json/JsonFile.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 08a91d2f3..343fbf155 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -64,6 +64,19 @@ class JsonFile */ public function write(array $hash) { + $dir = dirname($this->path); + if (!is_dir($dir)) { + if (file_exists($dir)) { + throw new \UnexpectedValueException( + $dir.' exists and is not a directory.' + ); + } + if (!mkdir($dir, 0777, true)) { + throw new \UnexpectedValueException( + $dir.' does not exist and could not be created.' + ); + } + } file_put_contents($this->path, json_encode($hash)); }