|
Posted by Gordon on April 14, 2008, 12:14 pm
Please log in for more thread options
I'm trying to remove a directory and all its contents from within a
script. I wrote a recursive function to take care of it, but when I
run it I get random "Directory not empty" error messages.
I dropped some code in to echo out the name of the file that's about
to be rmdir()ed or unoink()ed (depending if it's a file or a
directory) to see if it was choking on a particular subdirectory, but
doing that causes all the error messages to stop appearing!
It looks to me as if at some stages of the script the delete commands
are being issued too rapidly and the result is that an attempt to
delete a parent is made before its children have all been deleted.
The code I added to echo out the directory name first probably
introduces just enough of a delay for this problem to go away.
Obviously just doing something in the function to cause a delay isn't
a good solution, is there a better way of handling this problem?
I'm running PHP 5 on a Windows development machine through Apache.
Directory listings are being retrieved from a database.
|
|
Posted by =?ISO-8859-1?Q?=22=C1lvaro_G=2 on April 15, 2008, 8:32 am
Please log in for more thread options
Gordon escribió:
show/hide quoted text
> I'm trying to remove a directory and all its contents from within a
> script. I wrote a recursive function to take care of it, but when I
> run it I get random "Directory not empty" error messages.
In the manual page for unlink() there's a user comment with sample code
for recursive deletion. I haven't tried it but who knows:
http://php.net/unlink
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com -- Mi web de humor al baño María: http://www.demogracia.com --
|
|
Posted by The Natural Philosopher on April 15, 2008, 9:28 am
Please log in for more thread options Álvaro G. Vicario wrote:
show/hide quoted text
> Gordon escribió:
>> I'm trying to remove a directory and all its contents from within a
>> script. I wrote a recursive function to take care of it, but when I
>> run it I get random "Directory not empty" error messages.
>
> In the manual page for unlink() there's a user comment with sample code
> for recursive deletion. I haven't tried it but who knows:
>
> http://php.net/unlink
>
>
>
>
Normally thats because there are hidden or wrong permission files in it.
I suspect you need more subtle code, and if in Linux etc, some form of
attention to permissions if these are the problem.
|
|
Posted by Gordon on April 15, 2008, 10:02 am
Please log in for more thread options show/hide quoted text
> =C1lvaro G. Vicario wrote:
> > Gordon escribi=F3:
> >> I'm trying to remove a directory and all its contents from within a
> >> script. I wrote a recursive function to take care of it, but when I
> >> run it I get random "Directory not empty" error messages.
> > In the manual page for unlink() there's a user comment with sample code
> > for recursive deletion. I haven't tried it but who knows:
> >http://php.net/unlink
> Normally thats because there are hidden or wrong permission files in it.
> I suspect you need more subtle code, and if in Linux etc, some form of
> attention to permissions if these are the problem.
I don't think permissions are the problem, because the development
machine is Windows, and the error message being given is Directory Not
Empty. No Permission Denied errors are popping up in the output. I
also mentioned that the problem went away when I introduced a line of
code for debugging purposes into CmsItem::deleteItem(), which echos
the path being deleted to the output. My suspicion is that the calls
to rmdir are happening more rapidly than the filesystem can cope with
them. The debug code introduced just enough of a delay for the code
to work properly but without it attempts to delete a parent directory
can occur before the deletion of its children has completed, causing
the not empty error.
|
|
Posted by The Natural Philosopher on April 15, 2008, 10:27 am
Please log in for more thread options Gordon wrote:
show/hide quoted text
>> Álvaro G. Vicario wrote:
>>> Gordon escribió:
>>>> I'm trying to remove a directory and all its contents from within a
>>>> script. I wrote a recursive function to take care of it, but when I
>>>> run it I get random "Directory not empty" error messages.
>>> In the manual page for unlink() there's a user comment with sample code
>>> for recursive deletion. I haven't tried it but who knows:
>>> http://php.net/unlink
>> Normally thats because there are hidden or wrong permission files in it.
>> I suspect you need more subtle code, and if in Linux etc, some form of
>> attention to permissions if these are the problem.
>
> I don't think permissions are the problem, because the development
> machine is Windows, and the error message being given is Directory Not
> Empty. No Permission Denied errors are popping up in the output. I
> also mentioned that the problem went away when I introduced a line of
> code for debugging purposes into CmsItem::deleteItem(), which echos
> the path being deleted to the output. My suspicion is that the calls
> to rmdir are happening more rapidly than the filesystem can cope with
> them. The debug code introduced just enough of a delay for the code
> to work properly but without it attempts to delete a parent directory
> can occur before the deletion of its children has completed, causing
> the not empty error.
Ah. Caching.
I've had a similar problem with PHP creating a file that didn't actually
exist on disk till PHP exited.
So your are suggesting that PHP doesn't actually delete the files until
after the call to unlink the directory is received?
I would NOT be surprised. PHP'S file handling seems to be a bit flaky in
this area.
Windows should be capable of processing the calls as fast as they can be
sent: IT *should* simply block if the directory is still busy.
My guess - and its only a guess - is that PHP itself is caching the file
deletes. But not the directory deletes.
Or spitting them out in random order.
Maybe its possible to force a buffer flush in PHP.
|
| Similar Threads | Posted | | ftp_nlist returns false for empty directory instead of empty array | February 15, 2006, 1:10 pm |
| Prom deleting directory when using recursive mkdir | March 5, 2009, 9:27 am |
| How do you delete a zip file from a directory? | October 10, 2006, 9:19 pm |
| Delete a directory and all its files and sub-directories? | January 4, 2007, 4:31 pm |
| how to copy files from ftp directory to web-accessible directory? | November 21, 2006, 6:48 pm |
| List files from directory not in apache web directory | April 4, 2008, 5:17 am |
| Set directory permissions - directory already exists | January 9, 2007, 4:32 pm |
| setting error level for a particular directory / page | May 14, 2007, 1:02 pm |
| can't install PHP - keep getting "Invalid directory" error regarding the path to Apache httpd.h | June 24, 2006, 7:42 pm |
| 'echo "": No such file or directory" error using "exec" to pipe in PHP script | December 1, 2006, 11:53 am |
|
> script. I wrote a recursive function to take care of it, but when I
> run it I get random "Directory not empty" error messages.