Re: rmtree() is failing after some time
by cdarke (Prior) on Apr 23, 2009 at 07:21 UTC
|
Could be a permissions issue. Check $!, or you might have to run your script under strace or truss (if you have them) to get the real error. | [reply] |
|
|
I am a newbie in Perl. What is strace or truss?
Point here is that rmtree() is able to delete temp folders initially but after some time it starts giving this error. And I restart my perl program then also, initially it is able to delete them but after 20-25 folders it starts giving error.
My perl program creates threads(8-10), each thread creates a temp folder, processes it and then deletes it. Initially all threads behave well. After some time, error starts appearing.
| [reply] |
|
|
See strace/truss. It's a runtime call monitor for Perl, to find out where the problem is.
failed to fetch initial working directory
Is this the exact error message you get? I have a feeling that it's an issue with threading (you didn't mention in your post you use threads). Maybe you should post more code so we can take a look at it.
| [reply] |
|
|
|
|
|
|
|
|
|
Re: rmtree() is failing after some time
by Fletch (Bishop) on Apr 23, 2009 at 13:05 UTC
|
And while not directly germane to your problem your code has a problem:
You should be aware that checking for the existence of a file (or directory) and then doing something to/with that same file can introduce a race condition which can cause (at best) intermittent bugs or (worse) have security implications, so in general you shouldn't write code that way. It's better to go ahead and take the action and deal with a failure or exception if it occurs.
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] |
|
|
Maybe eventually its using same temp directory among two threads
| [reply] |
Re: rmtree() is failing after some time
by gwadej (Chaplain) on Apr 23, 2009 at 13:25 UTC
|
I know it will sound ridiculous, but make certain your current directory is not within the directory tree you are deleting.
I had this happen in a previous system where an in-house module was changing the directory on me. Under Linux, this did not cause an immediate problem (you can delete your current directory). On Windows, it caused an immediate failure.
| [reply] |
|
|
Before calling rmtree() I am already making sure that I change current directory to a directory that always exists and is not within the directory I am trying to delete.
| [reply] |
Re: rmtree() is failing after some time
by Anonymous Monk on Apr 23, 2009 at 09:34 UTC
|
| [reply] [d/l] |
Re: rmtree() is failing after some time
by spx2 (Deacon) on Apr 24, 2009 at 15:32 UTC
|
you can just do if(-e $tempDir) { `rm -rf $tempDir` } and you will fully benefit :) | [reply] [d/l] |