.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "docs::api::APR::Finfo 3pm" .TH docs::api::APR::Finfo 3pm 2024-03-29 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME APR::Finfo \- Perl API for APR fileinfo structure .SH Synopsis .IX Header "Synopsis" .Vb 3 \& use APR::Finfo (); \& use APR::Const \-compile => qw(FINFO_NORM); \& my $finfo = APR::Finfo::stat("/tmp/test", APR::Const::FINFO_NORM, $pool); \& \& $device = $finfo\->device; # (stat $file)[0] \& $inode = $finfo\->inode; # (stat $file)[1] \& # stat returns an octal number while protection is hex \& $prot = $finfo\->protection; # (stat $file)[2] \& $nlink = $finfo\->nlink; # (stat $file)[3] \& $gid = $finfo\->group; # (stat $file)[4] \& $uid = $finfo\->user; # (stat $file)[5] \& $size = $finfo\->size; # (stat $file)[7] \& $atime = $finfo\->atime; # (stat $file)[8] \& $mtime = $finfo\->mtime; # (stat $file)[9] \& $ctime = $finfo\->ctime; # (stat $file)[10] \& \& $csize = $finfo\->csize; # consumed size: not portable! \& \& $filetype = $finfo\->filetype; # file/dir/socket/etc \& \& $fname = $finfo\->fname; \& $name = $finfo\->name; # in filesystem case: \& \& # valid fields that can be queried \& $valid = $finfo\->valid; .Ve .SH Description .IX Header "Description" APR fileinfo structure provides somewhat similar information to Perl's \&\f(CWstat()\fR call, but you will want to use this module's API to query an already \f(CW\*(C`stat()\*(Aqed\*(C'\fR filehandle to avoid an extra system call or to query attributes specific to APR file handles. .PP During the HTTP request handlers coming after \&\f(CW\*(C`PerlMapToStorageHandler\*(C'\fR, \&\f(CW\*(C`$r\->finfo\*(C'\fR already contains the cached values from the apr's \f(CWstat()\fR call. So you don't want to perform it again, but instead get the \f(CW\*(C`ARP::Finfo\*(C'\fR object via: .PP .Vb 1 \& my $finfo = $r\->finfo; .Ve .SH API .IX Header "API" \&\f(CW\*(C`APR::Finfo\*(C'\fR provides the following functions and/or methods: .ie n .SS """atime""" .el .SS \f(CWatime\fP .IX Subsection "atime" Get the time the file was last accessed: .PP .Vb 1 \& $atime = $finfo\->atime; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $atime ( integer )" 4 .el .IP "return: \f(CW$atime\fR ( integer )" 4 .IX Item "return: $atime ( integer )" .PD Last access time in seconds since the epoch .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[8] .Ve .PP Note that this method may not be reliable on all platforms, most notably Win32 \-\- FAT32 filesystems appear to work properly, but NTFS filesystems do not. .ie n .SS """csize""" .el .SS \f(CWcsize\fP .IX Subsection "csize" Get the storage size consumed by the file .PP .Vb 1 \& $csize = $finfo\->csize; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $csize ( integer )" 4 .el .IP "return: \f(CW$csize\fR ( integer )" 4 .IX Item "return: $csize ( integer )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP Chances are that you don't want to use this method, since its functionality is not supported on most platforms (in which case it always returns 0). .ie n .SS """ctime""" .el .SS \f(CWctime\fP .IX Subsection "ctime" Get the time the file was last changed .PP .Vb 1 \& $ctime = $finfo\->ctime; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $ctime ( integer )" 4 .el .IP "return: \f(CW$ctime\fR ( integer )" 4 .IX Item "return: $ctime ( integer )" .PD Inode change time in seconds since the epoch .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[10] .Ve .PP The ctime field is non-portable. In particular, you cannot expect it to be a "creation time", see "Files and Filesystems" in the \&\fIperlport\fR manpage for details. .ie n .SS """device""" .el .SS \f(CWdevice\fP .IX Subsection "device" Get the id of the device the file is on. .PP .Vb 1 \& $device = $finfo\->device; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $device ( integer )" 4 .el .IP "return: \f(CW$device\fR ( integer )" 4 .IX Item "return: $device ( integer )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[0] .Ve .PP Note that this method is non-portable. It doesn't work on all platforms, most notably Win32. .ie n .SS """filetype""" .el .SS \f(CWfiletype\fP .IX Subsection "filetype" Get the type of file. .PP .Vb 1 \& $filetype = $finfo\->filetype; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $filetype ( "":filetype constant"" )" 4 .el .IP "return: \f(CW$filetype\fR ( \f(CW:filetype constant\fR )" 4 .IX Item "return: $filetype ( :filetype constant )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example: .PP .Vb 10 \& use APR::Pool; \& use APR::Finfo; \& use APR::Const \-compile => qw(FILETYPE_DIR FILETYPE_REG FINFO_NORM); \& my $pool = APR::Pool\->new(); \& my $finfo = APR::Finfo::stat("/tmp", APR::Const::FINFO_NORM, $pool); \& my $finfo = $finfo\->filetype; \& if ($finfo == APR::Const::FILETYPE_REG) { \& print "regular file"; \& } \& elsif ($finfo == APR::Const::FILETYPE_REG) { \& print "directory"; \& } \& else { \& print "other file"; \& } .Ve .PP Since \fI/tmp\fR is a directory, this will print: .PP .Vb 1 \& directory .Ve .ie n .SS """fname""" .el .SS \f(CWfname\fP .IX Subsection "fname" Get the pathname of the file (possibly unrooted) .PP .Vb 1 \& $fname = $finfo\->fname; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $filetype ( string )" 4 .el .IP "return: \f(CW$filetype\fR ( string )" 4 .IX Item "return: $filetype ( string )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .ie n .SS """group""" .el .SS \f(CWgroup\fP .IX Subsection "group" Get the group id that owns the file: .PP .Vb 1 \& $gid = $finfo\->group; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $gid ( number )" 4 .el .IP "return: \f(CW$gid\fR ( number )" 4 .IX Item "return: $gid ( number )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[5] .Ve .PP Note that this method may not be meaningful on all platforms, most notably Win32. Incorrect results have also been reported on some versions of OSX. .ie n .SS """inode""" .el .SS \f(CWinode\fP .IX Subsection "inode" Get the inode of the file. .PP .Vb 1 \& $inode = $finfo\->inode; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $inode ( integer )" 4 .el .IP "return: \f(CW$inode\fR ( integer )" 4 .IX Item "return: $inode ( integer )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[1] .Ve .PP Note that this method may not be meaningful on all platforms, most notably Win32. .ie n .SS """mtime""" .el .SS \f(CWmtime\fP .IX Subsection "mtime" The time the file was last modified .PP .Vb 1 \& $mtime = $finfo\->mtime; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $mtime ( integer )" 4 .el .IP "return: \f(CW$mtime\fR ( integer )" 4 .IX Item "return: $mtime ( integer )" .PD Last modify time in seconds since the epoch .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[9] .Ve .ie n .SS """name""" .el .SS \f(CWname\fP .IX Subsection "name" Get the file's name (no path) in filesystem case: .PP .Vb 1 \& $name = $finfo\->name; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $device ( string )" 4 .el .IP "return: \f(CW$device\fR ( string )" 4 .IX Item "return: $device ( string )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .ie n .SS """nlink""" .el .SS \f(CWnlink\fP .IX Subsection "nlink" Get the number of hard links to the file. .PP .Vb 1 \& $nlink = $finfo\->nlink; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $nlink ( integer )" 4 .el .IP "return: \f(CW$nlink\fR ( integer )" 4 .IX Item "return: $nlink ( integer )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[3] .Ve .ie n .SS """protection""" .el .SS \f(CWprotection\fP .IX Subsection "protection" Get the access permissions of the file. Mimics Unix access rights. .PP .Vb 1 \& $prot = $finfo\->protection; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $prot ( "":fprot constant"" )" 4 .el .IP "return: \f(CW$prot\fR ( \f(CW:fprot constant\fR )" 4 .IX Item "return: $prot ( :fprot constant )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[2] .Ve .PP Note: Perl's stat returns an octal number while mod_perl's \f(CW\*(C`protection\*(C'\fR returns a hex number. .PP See perldoc \-f stat and APR's file_io for more information on each. .ie n .SS """size""" .el .SS \f(CWsize\fP .IX Subsection "size" Get the size of the file .PP .Vb 1 \& $size = $finfo\->size; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $size ( integer )" 4 .el .IP "return: \f(CW$size\fR ( integer )" 4 .IX Item "return: $size ( integer )" .PD Total size of file, in bytes .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[7] .Ve .ie n .SS """stat""" .el .SS \f(CWstat\fP .IX Subsection "stat" Get the specified file's stats. .PP .Vb 1 \& $finfo = APR::Finfo::stat($fname, $wanted_fields, $p); .Ve .ie n .IP "arg1: $fname ( string )" 4 .el .IP "arg1: \f(CW$fname\fR ( string )" 4 .IX Item "arg1: $fname ( string )" The path to the file to \f(CWstat()\fR. .ie n .IP "arg2: $wanted_fields ( "":finfo constant"" )" 4 .el .IP "arg2: \f(CW$wanted_fields\fR ( \f(CW:finfo constant\fR )" 4 .IX Item "arg2: $wanted_fields ( :finfo constant )" The desired fields, as a bitmask flag of \&\f(CW\*(C`APR::FINFO_*\*(C'\fR constants. .Sp Notice that you can also use the constants that already combine several elements in one. For example \&\f(CW\*(C`APR::Const::FINFO_PROT\*(C'\fR asks for all protection bits, \&\f(CW\*(C`APR::Const::FINFO_MIN\*(C'\fR asks for the following fields: type, mtime, ctime, atime, size and \&\f(CW\*(C`APR::Const::FINFO_NORM\*(C'\fR asks for all atomic unix \f(CWapr_stat()\fR fields (similar to perl's \&\f(CWstat()\fR). .ie n .IP "arg3: $p ( ""APR::Pool object"" )" 4 .el .IP "arg3: \f(CW$p\fR ( \f(CWAPR::Pool object\fR )" 4 .IX Item "arg3: $p ( APR::Pool object )" the pool to use to allocate the file stat structure. .ie n .IP "ret: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "ret: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "ret: $finfo ( APR::Finfo object )" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example, here is how to get most of the \f(CW\*(C`stat\*(C'\fR fields: .PP .Vb 5 \& use APR::Pool (); \& use APR::Finfo (); \& use APR::Const \-compile => qw(FINFO_NORM); \& my $pool = APR::Pool\->new(); \& my $finfo = APR::Finfo::stat("/tmp/test", APR::Const::FINFO_NORM, $pool); .Ve .ie n .SS """user""" .el .SS \f(CWuser\fP .IX Subsection "user" Get the user id that owns the file: .PP .Vb 1 \& $uid = $finfo\->user; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "return: $uid ( number )" 4 .el .IP "return: \f(CW$uid\fR ( number )" 4 .IX Item "return: $uid ( number )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This method returns the same value as Perl's: .PP .Vb 1 \& (stat $filename)[4] .Ve .PP Note that this method may not be meaningful on all platforms, most notably Win32. .ie n .SS """valid""" .el .SS \f(CWvalid\fP .IX Subsection "valid" The bitmask describing valid fields of this apr_finfo_t structure including all available 'wanted' fields and potentially more .PP .Vb 1 \& $valid = $finfo\->valid; .Ve .ie n .IP "obj: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "obj: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "obj: $finfo ( APR::Finfo object )" .PD 0 .ie n .IP "arg1: $valid ( bitmask )" 4 .el .IP "arg1: \f(CW$valid\fR ( bitmask )" 4 .IX Item "arg1: $valid ( bitmask )" .PD This bitmask flag should be bit-OR'ed against \f(CW\*(C`:finfo constant\*(C'\fR constants. .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .SH "See Also" .IX Header "See Also" mod_perl 2.0 documentation. .SH Copyright .IX Header "Copyright" mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. .SH Authors .IX Header "Authors" The mod_perl development team and numerous contributors.