Perl/CGI uploader program - temp file not getting deleted
I have a Perl CGI program to upload zipped files to a server directory.
A temporary file is created in the /var/tmp/ directory. From my Googling I have learned that this file is supposed to get deleted automatically.
In my case this is not happening, hard disk space is getting squeezed. My client had the system up for over a month and they suddenly ran out of disk space. That is when I got the call. :)
The uploading itself is working fine.
The environment is Apache running on Linux.
1) What could possibly be causing this? Is there a setting somewhere, either in CGI, or Apache, or in the OS?
2) If the cause cannot be determined, how do I delete this each time the upload finishes?
Question 1 is the more important of the two. I would rather know the root cause and tackle that, than apply a bandaid solution.
Here is my code.
AFAIK, this 'automatic' cleaning is normally performed by a cron job, possibly running tmpwatch or some similar tool. Are you sure this is running? Is it running frequently enough? You will need to find a balance between how long to leave the files on the temporary directory, and how long they are required for your application.
If it is a cron job scheduled by the system administrators then I would have no control over that as it is my client's site. And they use a large commercial hosting company so they would have nothing to do with it either.
So I guess I should definitely delete it myself. I am not sure how to though, the unlink command requires a file name. Does anyone know how to determine the file name of this temp file at runtime? It seems to be "CGI" with a string of digits appended to it, different each time.
Well, surely this is your filename: $dirName/$fileName ?
iirc, if you unlink the file after you open it (but before you close it), in the same prog, the file will continue to exist until you close it, at which pt it will 'auto-magically' get deleted ie unlinked.
Just to make sure, I tried it and that was indeed the case. It has nothing to do with the temporary file.
Edit: By the way I am not using the object-oriented CGI.pm, like this line:
$tmpfilename = $query->tmpFileName($filename);
I am not sure it is available to me.
|All times are GMT -5. The time now is 02:50 PM.|