Browse Source

#663: Fix for emptying a directory which contains broken symbolic links

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2707 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 years ago
parent
commit
63feb3822c
1 changed files with 22 additions and 8 deletions
  1. 22 8
      setup/setuputils.class.inc.php

+ 22 - 8
setup/setuputils.class.inc.php

@@ -471,16 +471,30 @@ class SetupUtils
 			throw new Exception("Attempting to delete directory: '$dir'");
 		}
 
-		foreach(glob($dir . '/*') as $file)
+		$aFiles = scandir($dir); // Warning glob('.*') does not seem to return the broken symbolic links, thus leaving a non-empty directory
+		if ($aFiles !== false)
 		{
-			if(is_dir($file))
+			foreach($aFiles as $file)
 			{
-				self::tidydir($file);
-				rmdir($file);
-			}
-			else
-			{
-				unlink($file);
+				if (($file != '.') && ($file != '..'))
+				{
+					if(is_dir($dir.'/'.$file))
+					{
+						self::tidydir($dir.'/'.$file);
+						rmdir($dir.'/'.$file);
+					}
+					else
+					{
+						if (!unlink($dir.'/'.$file))
+						{
+							SetupPage::log("Warning - FAILED to remove file '$dir/$file'");
+						}
+						else if (file_exists($dir.'/'.$file))
+						{
+							SetupPage::log("Warning - FAILED to remove file '$dir/.$file'");
+						}
+					}
+				}
 			}
 		}
 	}