You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Geoffrey Young <gy...@laserlink.net> on 2001/07/03 14:03:56 UTC

some info missing from $r->finfo

hi guys...

  I tried using the -T and -B file tests against $r->finfo and found they
didn't work.  I'm guessing this is because -T and -B are special perl tests
that have to read in the file, and that Apache's stat() doesn't glean this
information on its own.

  so, is this a bug or a feature? :) from the looks of the mod_perl stuff, I
guess we would have to call our own stat() to get at it, which kinda defeats
the purpose.  maybe it's possible to run through only the -T stuff instead
of a full stat using some XS wizardry?

  anyway, another thing to consider for 2.0 :)

--Geoff

package Stat;

use Apache::Constants qw(OK);
use strict;

sub handler {
  my $r = shift;
  $r->send_http_header('text/plain');
  if (-f $r->finfo) {
  print "file ", $r->filename, " exists\n",
        "and must be either plain or binary...\n";
  print "it's binary" if -B $r->finfo;
  print "it's text" if -T $r->finfo;
  } else {
    print "no file... sorry";
  }
  return OK;
}
1;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: some info missing from $r->finfo

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 3 Jul 2001, Geoffrey Young wrote:

> hi guys...
> 
>   I tried using the -T and -B file tests against $r->finfo and found they
> didn't work.  I'm guessing this is because -T and -B are special perl tests
> that have to read in the file, and that Apache's stat() doesn't glean this
> information on its own.

i think those tests will work with this (untested) patch..

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.123
diff -u -r1.123 Apache.xs
--- src/modules/perl/Apache.xs	2001/06/14 05:26:28	1.123
+++ src/modules/perl/Apache.xs	2001/07/06 13:58:47
@@ -1956,9 +1956,11 @@
     statcache = r->finfo;
     if (r->finfo.st_mode) {
 	laststatval = 0;
+        sv_setpv(statname, r->filename);
     }
     else {
 	laststatval = -1;
+        sv_setpv(statname, "");
     }
     if(GIMME_V == G_VOID) XSRETURN_UNDEF;
     RETVAL = newRV_noinc((SV*)gv_fetchpv("_", TRUE, SVt_PVIO));
Index: src/modules/perl/perl_PL.h
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/perl_PL.h,v
retrieving revision 1.7
diff -u -r1.7 perl_PL.h
--- src/modules/perl/perl_PL.h	1999/01/18 03:26:19	1.7
+++ src/modules/perl/perl_PL.h	2001/07/06 13:58:47
@@ -19,6 +19,9 @@
 #ifndef laststatval
 #define laststatval PL_laststatval
 #endif
+#ifndef statname
+#define statname PL_statname
+#endif
 #ifndef rs
 #define rs PL_rs
 #endif


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org