[Customisation Database Commits] r944 - /trunk/titania/includes/tools/contrib_tools.php
Nathan Guse
exreaction at phpbb.com
Tue Mar 30 04:50:09 BST 2010
Author: exreaction
Date: Tue Mar 30 04:50:09 2010
New Revision: 944
Log:
Stop the indefinite loops when moving a directory to a subdirectory of itself (I am not sure of any better way to do this)
Modified:
trunk/titania/includes/tools/contrib_tools.php
Modified: trunk/titania/includes/tools/contrib_tools.php
==============================================================================
*** trunk/titania/includes/tools/contrib_tools.php (original)
--- trunk/titania/includes/tools/contrib_tools.php Tue Mar 30 04:50:09 2010
***************
*** 634,639 ****
--- 634,664 ----
$source = (substr($source, -1) == '/') ? $source : $source . '/';
$destination = (substr($destination, -1) == '/') ? $destination : $destination . '/';
+ if (strpos($destination, $source) !== false)
+ {
+ // Woh nelly, this will loop infinitely without some special care!
+
+ $temp_destination = substr($source, 0, strrpos($source, '/', -2)) . '/temp/';
+ $i = 1;
+ while (file_exists($temp_destination . $i))
+ {
+ $i++;
+ }
+ $temp_destination .= $i;
+
+ // Move to temp directory
+ $this->mvdir_recursive($source, $temp_destination);
+
+ // Remove source directory
+ $this->rmdir_recursive($source);
+
+ // Move from temp directory to the final directory
+ $this->mvdir_recursive($temp_destination, $destination);
+
+ // Remove temp directory
+ $this->rmdir_recursive($temp_destination);
+ }
+
if (!is_dir($source))
{
return false;
More information about the customisationdb-commits
mailing list