On Tue, 22 Aug 2000, Jens-Uwe Mager wrote:

> I am looking for a way to update the reported size of a file in a plain
> directory index generated by Apache. I have installed a perl fixup
> handler that does check if a Macintosh resource fork is available
> additionally to the plain data fork and it replaces the default content
> handler with a custom one that combines both the data and resource fork
> on the fly in the MacBinary archive format. This all runs fine and well.
> 
> The problem I have now that I need to modify the displayed size in the
> directory index. For example if the file in question is a Mac resource
> file with no data area the directory index displays 0k as the plain data
> file really has a zero length. I would believe that I need to delve into
> the C innards of the request record and add the size of the resource
> fork to the st_size field of the stat record to fix this, or does
> anybody have any better idea how to do this in plain perl?

i probably shouldn't be 'working' on xmas, but have some time to kill
before the airport and have had this in mind since you first posted (4
months ago!).  with the patch below and this package:
http://perl.apache.org/~dougm/Sys-Stat-0.01.tar.gz

a fixup handler can modify the reported size like so:

sub MyFixup::handler {
    my $r = shift;
    my $stat = Sys::Stat->stat($r->filename);
    $stat->size(10_000); #whatever size
    $r->finfo($stat); #changed size will be reflected in dirindex output
    0;
}

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.118
diff -u -r1.118 Apache.xs
--- src/modules/perl/Apache.xs  2000/12/22 20:56:24     1.118
+++ src/modules/perl/Apache.xs  2000/12/26 02:02:13
@@ -1906,10 +1906,26 @@
 #  struct stat finfo;          /* ST_MODE set to zero if no such file */
 
 SV *
-finfo(r)
+finfo(r, sv_statbuf=Nullsv)
     Apache r
+    SV *sv_statbuf
 
     CODE:
+    if (sv_statbuf) {
+        if (SvROK(sv_statbuf) && SvOBJECT(SvRV(sv_statbuf))) {
+            STRLEN sz;
+            char *buf = SvPV((SV*)SvRV(sv_statbuf), sz);
+            if (sz != sizeof(r->finfo)) {
+                croak("statbuf size mismatch, got %d, wanted %d",
+                      sz, sizeof(r->finfo));
+            }
+            memcpy(&r->finfo, buf, sz);
+        }
+        else {
+            croak("statbuf is not an object");
+        }
+    }
+
     statcache = r->finfo;
     if (r->finfo.st_mode) {
        laststatval = 0;

Reply via email to