Skip to content

Commit

Permalink
Implemented #116: Rename "commithook files:allow-default" to "commith…
Browse files Browse the repository at this point in the history
…ook files allow-default"

 - Added catching php error exceptions. Pushed to using dirname() func.
  • Loading branch information
andkirby committed Aug 30, 2016
1 parent b2b116a commit c7ecca6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/PreCommit/Console/Helper/Config/WriterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ public function write($config, $file)
*/
public function writeContent($file, $content)
{
$dir = pathinfo($file, PATHINFO_DIRNAME);
if (!is_dir($dir) && !mkdir($dir, 770, true)) {
throw new Exception('Cannot create directory \''.$dir.'\'.');
$dir = dirname($file);

try {
if (!is_dir($dir) && !mkdir($dir, 770, true)) {
throw new Exception("Cannot create directory '$dir' (file: $file).");
}
} catch (\Exception $e) {
throw new Exception("Cannot create directory '$dir' (file: $file).");
}

if (!file_put_contents($file, $content)) {
throw new Exception("Cannot write file '$file'.");
}
Expand Down

0 comments on commit c7ecca6

Please sign in to comment.