Welcome! » Log In » Create A New Profile

When Cache.SerializerPermissions is NULL HTMLPurifier fails when creating subfolders...

Posted by Richard Hagen 

Hi,

When Cache.SerializerPermissions is NULL, I get an exeption when creating subfolders:

ContextErrorException: User Warning: Base directory /home/eportal/production/releases/20160822093255/app/../cache/htmlpurifier does not exist,
please create or change using %Cache.SerializerPath
[eportal@vps htmlpurifier]$ cd /home/eportal/production/releases/20160822093255/app/../cache/htmlpurifier
[eportal@vps htmlpurifier]$ ll -a
total 8
drwxrwxrwx 2 eportal eportal 4096 Aug 22 11:32 .
drwxrwxrwx 3 eportal eportal 4096 Aug 22 11:32 ..
[eportal@vps htmlpurifier]$ 

There seems to be a logical error in Serializer.php@232-239:

            if ($chmod === null) {
                trigger_error(
                    'Base directory ' . $base . ' does not exist,
                    please create or change using %Cache.SerializerPath',
                    E_USER_WARNING
                );
                return false;
            }

Richard

Please test the following patch and let me know if it fixes your problem.

diff --git a/library/HTMLPurifier/DefinitionCache/Serializer.php b/library/HTMLPurifier/DefinitionCache/Serializer.php
index f930c6b..9fcd5a4 100644
--- a/library/HTMLPurifier/DefinitionCache/Serializer.php
+++ b/library/HTMLPurifier/DefinitionCache/Serializer.php
@@ -217,6 +217,11 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
     {
         $directory = $this->generateDirectoryPath($config);
         $chmod = $config->get('Cache.SerializerPermissions');
+        if ($chmod === null) {
+            // TODO: This races
+            if (is_dir($directory)) return true;
+            return mkdir($directory);
+        }
         if (!is_dir($directory)) {
             $base = $this->generateBaseDirectoryPath($config);
             if (!is_dir($base)) {
@@ -229,25 +234,14 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
             } elseif (!$this->_testPermissions($base, $chmod)) {
                 return false;
             }
-            if ($chmod === null) {
+            if (!mkdir($directory, $chmod)) {
                 trigger_error(
-                    'Base directory ' . $base . ' does not exist,
-                    please create or change using %Cache.SerializerPath',
+                    'Could not create directory ' . $directory . '',
                     E_USER_WARNING
                 );
                 return false;
             }
-            if ($chmod !== null) {
-                mkdir($directory, $chmod);
-            } else {
-                mkdir($directory);
-            }
             if (!$this->_testPermissions($directory, $chmod)) {
-                trigger_error(
-                    'Base directory ' . $base . ' does not exist,
-                    please create or change using %Cache.SerializerPath',
-                    E_USER_WARNING
-                );
                 return false;
             }
         } elseif (!$this->_testPermissions($directory, $chmod)) {

Sorry, you do not have permission to post/reply in this forum.