Page 1 of 1

[2.0] Upgrader throws exception

Posted: Wed Apr 16, 2014 7:55 pm
by mattsches
Tried to upgrade my local dev blog from 1.7.8 to the latest revision from the Github 2.0 branch. The upgrade failed with the following error

Code: Select all

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/var/www/vhosts/s9y.local/httpdocs/htmlarea/contrib): failed to open dir: No such file or directory' in /home/mattsches/var/www/vhosts/s9y.local/httpdocs/include/functions_upgrader.inc.php on line 292
Proposed patch (sorry, I'm in a hurry, no time to properly commit this)

Code: Select all

Index: include/functions_upgrader.inc.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- include/functions_upgrader.inc.php	(revision 31eba101f630ec428a5975e4163a270833784eda)
+++ include/functions_upgrader.inc.php	(revision )
@@ -163,8 +163,12 @@
  */
 function recursive_directory_iterator($dir = array()) {
     foreach ($dir AS $path) {
+        try {
-        serendipity_removeDeadFiles_SPL($path);
-        @rmdir($path);
+            serendipity_removeDeadFiles_SPL($path);
+            @rmdir($path);
+        } catch (Exception $e) {
+            echo htmlspecialchars($path) . " >> Maybe file or directory did not exist.<br/>";
+        }
     }
 }
Cheers, mattsches

Re: [2.0] Upgrader throws exception

Posted: Wed Apr 16, 2014 11:47 pm
by mattsches
Ok, fixed and committed. 8)

Re: [2.0] Upgrader throws exception

Posted: Thu Apr 17, 2014 10:07 am
by Timbalu
I don't think this will help. Since it seems essentially a problem with the SPL RecursiveDirectoryIterator::__construct(#PATH#).

What makes me wonder what is wrong with or why you didn't have these old htmlarea directories belonging to old Xinha...

In your case it called '/var/www/vhosts/s9y.local/httpdocs/htmlarea/contrib'. The directory seemed to exists, else the first line if (!is_dir($dir)) return; in serendipity_removeDeadFiles_SPL() would have run, which is before the SPL RecursiveDirectoryIterator construct.

Maybe that is a special environment question? And is related to issue #116? Or (which is my favourite) it has to do with wrong write permissions of /dirs and its subdirs? Then we should better move the try {} catch {} block into serendipity_removeDeadFiles_SPL() or try to fix permissions.

What do you think?

Re: [2.0] Upgrader throws exception

Posted: Thu Apr 17, 2014 10:14 am
by garvinhicking
Hi!

Something definitely is fishy with this removal of dead files, like https://github.com/s9y/Serendipity/issu ... t-40619307 -- I'd love to have a fix that would prevent errors like these. However, I'm not able to reproduce this?!

So yeah, I agree, we should probably move this try/catch to the SPL function itself...

Re: [2.0] Upgrader throws exception

Posted: Thu Apr 17, 2014 2:24 pm
by Timbalu
Nor me.

If it really is my (favourite) permission guess, I'd like to better have a break in front eg

Code: Select all

if (!is_readable($dir) || !is_dir($dir)) return;
(untested) and not try/catch returning various error strings.

Or use this (mattsches please test):

Code: Select all

function serendipity_removeDeadFiles_SPL($dir=null, $deadfiles=null, $purgedir=null, $list_only=false) {
    try {
        $_dir = new RecursiveDirectoryIterator($dir);
    // NOTE: UnexpectedValueException thrown for PHP >= 5.3
    } catch (Exception $e) {
        return 0;
    }
    $iterator = new RecursiveIteratorIterator($_dir, RecursiveIteratorIterator::CHILD_FIRST);
    #$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
    ...
which btw is the way also Smarty avoids possible error exceptions.

Re: [2.0] Upgrader throws exception

Posted: Wed Apr 23, 2014 6:50 pm
by Timbalu
@mattsches
I still think the last is the best, could you test and change that?

Re: [2.0] Upgrader throws exception

Posted: Wed Apr 23, 2014 11:12 pm
by mattsches
Looks good to me, and I agree with moving it to `serendipity_removeDeadFiles_SPL`; but I have not tested it yet.

Could actually have been a permission problem of some kind because otherwise `is_dir($dir)` should have bailed out. I'm not sure anymore. I will try to reproduce the problem.

Mattsches

Re: [2.0] Upgrader throws exception

Posted: Thu Apr 24, 2014 2:05 pm
by garvinhicking
Great, thanks to you guys!

Re: [2.0] Upgrader throws exception

Posted: Thu Apr 24, 2014 7:11 pm
by Timbalu
Commited.
@mattsches Since I could not reproduce this error by myself, it might still need an eye on this fix.
But I did some research on this 'UnexpectedValueException' message and it seemed to be caused by the RecursiveIteratorIterator() and follow-up CHILD_FIRST. The latter was a need to have.

Without having a real test case, I would better not return any failing message, since I don't know how this could get in conflict with the upgraders routine. But I think this are very rare cases, where this error could happen at all.