From caec0abcfc003a77378184a15b1d5c5e008a900e Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Sat, 25 May 2013 22:32:07 +0200 Subject: [PATCH] Fix for ExtractTask does not check output directory (ticket 3852) --- lib/Cake/Console/Command/Task/ExtractTask.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index db1ddbcaa..37ce302f6 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -208,7 +208,7 @@ class ExtractTask extends AppShell { if (strtoupper($response) === 'Q') { $this->out(__d('cake_console', 'Extract Aborted')); $this->_stop(); - } elseif (is_dir($response)) { + } elseif ($this->_isPathUsable($response)) { $this->_output = $response . DS; break; } else { @@ -229,7 +229,13 @@ class ExtractTask extends AppShell { if (empty($this->_files)) { $this->_searchFiles(); } + $this->_output = rtrim($this->_output, DS) . DS; + if (!$this->_isPathUsable($this->_output)) { + $this->out(__d('cake_console', 'The output directory %s was not found or writable.', $this->_output)); + return $this->_stop(); + } + $this->_extract(); } @@ -752,4 +758,13 @@ class ExtractTask extends AppShell { return $this->_paths === array(APP); } +/** + * Checks whether or not a given path is usable for writing. + * + * @param string $path Path to folder + * @return boolean true if it exists and is writable, false otherwise + */ + protected function _isPathUsable($path) { + return is_dir($path) && is_writable($path); + } }