[2.0] Upgrader throws exception

Having trouble installing serendipity?
Post Reply
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

[2.0] Upgrader throws exception

Post 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
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Re: [2.0] Upgrader throws exception

Post by mattsches »

Ok, fixed and committed. 8)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Upgrader throws exception

Post 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?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Upgrader throws exception

Post 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...
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Upgrader throws exception

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Upgrader throws exception

Post by Timbalu »

@mattsches
I still think the last is the best, could you test and change that?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Re: [2.0] Upgrader throws exception

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Upgrader throws exception

Post by garvinhicking »

Great, thanks to you guys!
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Upgrader throws exception

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply