Bug #55468 [Com]: UnexpectedValueException caused by an unreleased handle or something

From: Date: Sat, 08 Sep 2012 14:04:17 +0000
Subject: Bug #55468 [Com]: UnexpectedValueException caused by an unreleased handle or something
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173248@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55468&edit=1 ID: 55468 Comment by: sephirot_germany at hotmail dot com Reported by: php at tracking-celebs dot info Summary: UnexpectedValueException caused by an unreleased handle or something Status: Open Type: Bug Package: SPL related Operating System: win32 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Description: ------------ I have same problem, When I calculate size of root folder after delete sub folder error will come. I think Iterator use old reference. Test script: --------------- $rootPath = "C:\public/upload"; $path = "C:\public/upload/New Folder"; // Path to delete folder $Recursive1 = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST); // Delete all subfolder foreach ($Recursive1 as $object) { if ($object->isDir()) { rmdir($object->__toString()); } else { unlink($object->__toString()); } } rmdir($path); // Delete this Folder // Calculate root folder size $size = 0 $Recursive2 = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ); // Error here foreach($Recursive2 as $object){ $size += is_file($object->getPath()) ? filesize($object->getPath()):0; } Previous Comments: ------------------------------------------------------------------------ [2011-08-25 00:06:26] php at tracking-celebs dot info Permissions aren't a problem here. Besides, the (first, $foo) folder actually gets removed (as indicated by the output of file_exists), that's not the problem. And the problem comes before trying to remove the other one ($folder), it is that when calling the iterator (on that parent), because it'll somehow still "hold"/find a reference to the now non-existing/freshly removed folder, thus causing the exception... ------------------------------------------------------------------------ [2011-08-22 13:58:59] kalle@php.net At first glance it doesn't looks like a problem in PHP itself but more that you haven't granted yourself the permission to delete the folder on Windows. Have you tried to chmod or similar it? ------------------------------------------------------------------------ [2011-08-20 19:56:20] php at tracking-celebs dot info Description: ------------ After using a DirectoryIterator on a folder, then removing said folder, using another iterator to iterate on the folder's parent will see/try to look into the removed folder. This only happens on Windows, so maybe due to a cache somewhere or something. Tried adding a clearstatcache() just in case, but that doesn't change anything. FYI if you replace the first DirectoryIterator by a: opendir($foo); without calling closedir() you get the same error, hence why I suggested it might be a handle not (properly) released or something. Test script: --------------- <?php $folder = 'V:\\tmp\\foobar'; if (file_exists($folder)) die("$folder already exists"); if (!mkdir($folder)) die("unable to create $folder"); $foo = $folder . '\\foo'; if (!mkdir($foo)) die("unable to create $foo"); $iterator = new DirectoryIterator($foo); foreach ($iterator as $fi) { } unset($iterator); if (!rmdir($foo)) die("unable to delete $foo"); var_dump(file_exists($foo)); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder), RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $fi) { } unset($iterator); if (!rmdir($folder)) die("unable to delete $folder"); Expected result: ---------------- bool(false) Actual result: -------------- bool(false) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(V:\tmp\foobar\foo,V:\tmp\foobar\foo): Access is denied. (code: 5)' in V:\test\test.php on line 35 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55468&edit=1

« previous php.bugs (#173248) next »