Skip to content
Browse files

Confirm that build directory is writeable on Assets::__construct()

One common silent failures of this subsystem (either during installation or
deployment) based on other Kohana modules is likely to be the build-directory
not being writeable. Prior to this, this could only cause a failure at the
point of calling Assets::generate_package_file(), and even then the
failure is easily missed in a typical web application since CSS/JS 404s
aren't considered fatal exceptions.

Permissions-management is a frequent source of frustration for many
administrators. During deployment it's not uncommon for permissions to be
lost, or to be inconsistent between environments.

I've updated the class to be similar to the DB, Cache, and Logging classes,
which throw fatal exceptions if they are loaded in environments that
are hostile to their operation (e.g., writable directories not writable,
databases that can't be connected to, cache engines that are unavailable, etc.).

Because this happens in __construct() (which is only called once per
execution thanks to the static factory method Assets::instance()), and
the fact that once a file is built Kohana's .htaccess will preclude
the need to call the build action again, this extra check will be
acceptably cheap.
  • Loading branch information...
1 parent 9eddb9c commit 7bca4b62270700862f03ef662ce8a06c6a2a666c @fleep fleep committed Feb 27, 2012
Showing with 5 additions and 0 deletions.
  1. +5 −0 classes/assets.php
View
5 classes/assets.php
@@ -17,6 +17,11 @@ public function __construct()
{
$this->config = Kohana::config('assets');
+ // Confirm that the build directory is writeable
+ if (!is_writable($this->config['dir_build'])) {
+ throw new Kohana_Exception ($this->config['dir_build'].' must be writable.');
+ }
+
$this->data['css'] = array();
$this->data['js'] = array();

0 comments on commit 7bca4b6

Please sign in to comment.
Something went wrong with that request. Please try again.