From e2c4f5b7e1bf28171939e2642bbe3eddd83594d7 Mon Sep 17 00:00:00 2001 From: dantleech Date: Fri, 11 Jul 2014 23:20:11 +0200 Subject: [PATCH] Error on non-eistant file and expand path for profile - Throw an exception if the file specified by `db-path` does not exist. - Always expand the path to an absolute path for storage in profile. --- CHANGELOG.md | 5 +++++ .../ProfileFromSessionInputSubscriber.php | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc469e10..09dac9bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ alpha-4 - [args] 28 instances of bad InputArgument constructor fixed - [node] `node:list` Catch exceptions when rendering property rows (e.g. on invalid references) +### Improvements + +- [connect] Always expand relative paths for `db-path` +- [connect] Throw exception if file indicated by `db-path` does not exist. + alpha-3 ------- diff --git a/src/PHPCR/Shell/Subscriber/ProfileFromSessionInputSubscriber.php b/src/PHPCR/Shell/Subscriber/ProfileFromSessionInputSubscriber.php index 1f1dc331..eeb6cd4d 100644 --- a/src/PHPCR/Shell/Subscriber/ProfileFromSessionInputSubscriber.php +++ b/src/PHPCR/Shell/Subscriber/ProfileFromSessionInputSubscriber.php @@ -38,7 +38,26 @@ public function handleProfileInit(ProfileInitEvent $e) ); foreach ($transportOptions as $optionName => $configName) { - $profile->set('transport', $configName, (string) $input->getOption($optionName)); + $value = $input->getOption($optionName); + + if (null !== $value) { + // sanitize some input values + switch ($optionName) { + case 'db-path': + if (!file_exists($value)) { + throw new \InvalidArgumentException(sprintf( + 'DB file "%s" does not exist.' + , $value)); + } + + $value = realpath(dirname($value)) . DIRECTORY_SEPARATOR . basename($value); + break; + default: + // all good + } + } + + $profile->set('transport', $configName, (string) $value); } foreach ($phpcrOptions as $optionName => $configName) {