Re: Weird file permission problem with File::Temp
[prev]
[thread]
[next]
[Date index for 2004/11/23]
--------------070408080700090103010806
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit
RobertCZ wrote:
> Stas Bekman wrote:
>
>> RobertCZ wrote:
>>
>>> I'm trying to create temp file in PerlFixupHandler using File::Temp,
>>> write to it, send it to the client and get the temp file
>>> automatically unlinked upon the end of the request.
>>> I keep getting file permission error.
>>
>> 2) you said:
>> $fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );
>> so by the time the response phase comes, the file is not there anymore.
>>
>> instead you could use the approach explained here:
>> http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler
>>
>> or simply use the response phase and sendfile() to send the contents.
>
>
> This *|cleanup_register()|* trick works great, thank you very much, I
> have spent way too much time on this thing...
>
> I'm not sure why Gerald Richter uses PerlFixupHandler but I guess he
> has his reason, so I don't want to fool with it. (it's
> Apache::ImageMagick module I'm trying to port)
>
> I have however one more question (I've posted this in other email, but
> it's related): In this FixupHandler when I create a new file and use
> it with $r -> filename ($tmpnam) , Apache still thinks size is that
> of the originally requested file. Is there a way to change it? Thanks
> again.
Geoff just answered, so just for the archives:
>well, you message is sufficiently vague since I don't have the
>Apache::ImageMagick code handy :)
>
>but I suspect that you mean that the module sets $r->filename and with mp1
>the new filename's stat info is updated, but with mp2 it is not? if so,
>yes, this is proper - mp1 did magic behind the scenes for you.
>
>with mp2 you need to update the stat info yourself each time you update
>$r->filename. something like this:
>
> $r->filename($newfile);
> $r->finfo(APR::Finfo::stat($newfile, APR::FINFO_NORM, $r->pool));
>
>
--------------070408080700090103010806
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
RobertCZ wrote:
<blockquote cite="mid41A32A25.8010200@xxxxxx.xx" type="cite">
<meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
<title></title>
Stas Bekman wrote:
<blockquote cite="mid41A2C5D0.1060705@xxxxxx.xxx" type="cite">RobertCZ
wrote: <br>
<blockquote type="cite">I'm trying to create temp file in
PerlFixupHandler using File::Temp, write to it, send it to the client
and get the temp file automatically unlinked upon the end of the
request. <br>
I keep getting file permission error. <br>
</blockquote>
2) you said: <br>
$fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 ); <br>
so by the time the response phase comes, the file is not there anymore.
<br>
<br>
instead you could use the approach explained here: <br>
<a class="moz-txt-link-freetext"
href="http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler">http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler</a>
<br>
or simply use the response phase and sendfile() to send the contents. <br>
</blockquote>
<br>
This <b><code>cleanup_register()</code></b> trick works great, thank
you very much, I have spent way too much time on this thing...<br>
<br>
I'm not sure why Gerald Richter uses PerlFixupHandler but I guess he
has his reason, so I don't want to fool with it. (it's
Apache::ImageMagick module I'm trying to port)<br>
<br>
I have however one more question (I've posted this in other email, but
it's related): In this FixupHandler when I create a new file and use it
with $r -> filename ($tmpnam) , Apache still thinks size is that of
the originally requested file. Is there a way to change it? Thanks
again.<br>
</blockquote>
<br>
Geoff just answered, so just for the archives:<br>
<blockquote type="cite">
<pre wrap="">well, you message is sufficiently vague since I don't have the
Apache::ImageMagick code handy :)
but I suspect that you mean that the module sets $r->filename and with mp1
the new filename's stat info is updated, but with mp2 it is not? if so,
yes, this is proper - mp1 did magic behind the scenes for you.
with mp2 you need to update the stat info yourself each time you update
$r->filename. something like this:
$r->filename($newfile);
$r->finfo(APR::Finfo::stat($newfile, APR::FINFO_NORM, $r->pool));
</pre>
</blockquote>
<br>
</body>
</html>
--------------070408080700090103010806--