hi all
just following up on a thread in new-httpd from the weekend :)
in mp1, whenever a user set the filename via $r->filename($newfile) mod_perl would update r->finfo as well. the reason is because things like default_handler do this
ap_update_mtime(r, r->finfo.mtime); ... ap_set_content_length(r, r->finfo.size); if ((errstatus = ap_meets_conditions(r)) != OK) { ...
so, if a handler sets r->filename after translation, the wrong value will be used in the meets_conditions test, and the client will get bad data.
+1, but won't be better for Apache provide an API to set r->filename which will take care of updating finfo? If Apache doesn't provide this API, and wants users to do that when they really want to (as it involves an overhead), perhaps we shouldn't do that as we did in mp1 but instead document that one has to update $r->finfo, if they need to and leave things 1:1 with C API.
Another idea would be to provide a variation of filename() which will set filename and update finfo. e.g. filename_finfo()?
the attached patch carries this over to mp2.
the only outstanding issue for me is that in mp1, there was an exception for Win32, which I didn't carry over, figuring apr now takes care of the compat issues. I'm also hoping that utime (used in the test suite) is portable :) so, I'd like to get some feedback/test results from Win32 before porting this functionality to mp2.
From perlport.pod:
utime LIST
Only the modification time is updated. (BeOS, Mac OS, VMS,
RISC OS) May not behave as expected. Behavior depends on the C runtime
library's implementation of utime(), and the filesystem being
used. The FAT filesystem typically does not support an "access
time" field, and it may limit timestamps to a granularity of
two seconds. (Win32)So it looks like you are safe, since all we want is the mod time.
And a few comments on the patch:
Index: xs/Apache/RequestRec/Apache__RequestRec.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/Apache/RequestRec/Apache__RequestRec.h,v
retrieving revision 1.6
diff -u -r1.6 Apache__RequestRec.h
--- xs/Apache/RequestRec/Apache__RequestRec.h 14 Mar 2003 05:34:24 -0000 1.6
+++ xs/Apache/RequestRec/Apache__RequestRec.h 27 Oct 2003 19:13:13 -0000
@@ -53,3 +53,33 @@
return modperl_table_get_set(aTHX_ r->subprocess_env,
key, val, TRUE);
}
+
+static MP_INLINE
+char *mpxs_Apache__RequestRec_filename(pTHX_ request_rec *r, + SV *name)
+{
+ char *retval = r->filename;
+
+ if (name) {
+ STRLEN len;
+ const char *val = SvPV(name, len);
+
+ MP_TRACE_o(MP_FUNC, "setting r->filename to %s\n", + val);
If you intend to keep these traces, they shouldn't be _o, which is used for I/O tracing. _h (handlers) could be an OK choice, but may be introducing _a (Apache interaction?) is a better idea?
[...]--- /dev/null 2003-01-30 05:24:37.000000000 -0500 +++ t/modperl/filename.t 2003-10-27 11:46:00.000000000 -0500
+ok utime(undef, undef, catfile(qw(htdocs index.html))); +ok utime(undef, undef, catfile(qw(htdocs modperl change.html)));
please don't hardcode 'htdocs', see other tests that work with files, using Apache::Test->config->vars->{documentroot}
[...]
+# touch index.html so that requests to it get 200 +# when using the old Last-Modified date + +sleep 2; # make sure we get a time difference
It's probably better to use the approach used in t/hooks/cleanup2.t, so you sleep the minimal amount of time using a more finegrained select and checking for the timestamp with -M will ensure that it'll certainly be different (in case some OS has a bad sleep granularity).
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
