Jump to content

Cache Directory Writable Test


Adam

Recommended Posts

We are installing Blesta 4.0.0 and notice that during the installation process an alert was issued saying that our cache directory was not writable. This was strange to us because in our environment, the user who runs PHP has write access (we use suPHP for security reasons).

 

Upon closer look we notice that Blesta 4.0.0 does not ship with an empty cache directory (as defined by CACHEDIR). Rather, the code assumes that the cache directory already exists. You can see this below:
 

app/controllers/install.php
807             'cache_writable' => [
808                 'message' => Language::_('SystemRequirements.!warning.cache_writable.recommended', true, CACHEDIR),
809                 'req' => true,
810                 'cur' => is_writable(CACHEDIR)
811             ], // To cache view files for performance

The PHP function is_writable does two things: checks if the user can write AND if the file exists. Since Blesta does not ship with an empty CACHEDIR (nor was anything mentioned to create one in the README), we get an error for no reason.

 

Below is a patch for a proposed fix. It checks to see if a file exists, if it does, then performs the is_writable test. Otherwise, attempt to create a directory and check if we can write to it The second test is probably pointless cause if you can create a directory you should be able to write to it, but edge cases can be tricky if parent folder has sticky bits enable, etc.

-Adam

 

diff --git a/app/controllers/install.php b/app/controllers/install.php
index a6c462e..414d3a8 100644
--- a/app/controllers/install.php
+++ b/app/controllers/install.php
@@ -807,7 +807,7 @@ class Install extends Controller
             'cache_writable' => [
                 'message' => Language::_('SystemRequirements.!warning.cache_writable.recommended', true, CACHEDIR),
                 'req' => true,
-                'cur' => is_writable(CACHEDIR)
+                'cur' => (file_exists(CACHEDIR)) ? is_writable(CACHEDIR) : (mkdir(CACHEDIR, 0755) && is_writable(CACHEDIR)) ? true : false
             ], // To cache view files for performance
             'ext-simplexml' => [
                 'message' => Language::_('SystemRequirements.!warning.simplexml.recommended', true),

 

Link to comment
Share on other sites

  • 1 month later...
8 hours ago, Paul said:

Because the cache directory was empty, it was removed automatically by our build process. This was corrected in CORE-2366 for the full build of 4.0.1, and will ship with full builds going forward.

Awesome! Thanks for the update.

-Adam

Link to comment
Share on other sites

  • Tyson locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...