-f 文件测试运算符在 mod_perl 中工作吗?
我正在尝试使用 Tenjin 模块,但它失败了,因为它找不到模板文件,但它存在。我已经在模块中添加了一些调试语句,
return $filepath if (-f $filepath);
即使 $filepath 正确,它也不会通过。我已经在独立脚本中尝试过,它工作正常,但是当我将其复制到 mod_perl 脚本时,它失败了。有什么想法吗?
$filepath 是完整的绝对路径: /something/another/dir/2/filename.plhtml
这是模块的函数。注意我的“调试”...它打印了文件的正确路径,即 777,但它从不打印“是”。
sub find_template_file {
my ($this, $filename) = @_;
my $path = $this->{path};
if ($path) {
my $sep = $^O eq 'MSWin32' ? '\\\\' : '/';
foreach my $dirname (@$path) {
my $filepath = $dirname . $sep . $filename;
print STDERR "--$filepath--\n";
if (-f $filepath){
print STDERR "--- YES ---\n\n";
}
return $filepath if (-f $filepath);
}
} else {
return $filename if (-f $filename);
}
my $s = $path ? ("['" . join("','", @$path) . "']") : '[]';
die "Tenjin::Engine: $filename not found (path=$s).";
:
Tenjin::Engine 失败
找不到 index.plhtml (path=['/var/2.0/templates/search'])。位于 /usr/lib/perl5/site_perl/5.8.8/Tenjin/Engine.pm 第 56 行。\n
I'm trying to use the Tenjin module but it fails because it can't find the template file but it exists. I've added some debug statements into the module and it's not passing
return $filepath if (-f $filepath);
even when $filepath is correct. I've tried in a standalone script and it works fine but when I copy it to the mod_perl script it fails. Any ideas?
$filepath is a full absolute path: /something/another/dir/2/filename.plhtml
This is the function form the module. Notice my "Debug"...it prints the correct path to the file which is 777 but it never prints YES.
sub find_template_file {
my ($this, $filename) = @_;
my $path = $this->{path};
if ($path) {
my $sep = $^O eq 'MSWin32' ? '\\\\' : '/';
foreach my $dirname (@$path) {
my $filepath = $dirname . $sep . $filename;
print STDERR "--$filepath--\n";
if (-f $filepath){
print STDERR "--- YES ---\n\n";
}
return $filepath if (-f $filepath);
}
} else {
return $filename if (-f $filename);
}
my $s = $path ? ("['" . join("','", @$path) . "']") : '[]';
die "Tenjin::Engine: $filename not found (path=$s).";
}
Fails with
Tenjin::Engine: index.plhtml not found (path=['/var/2.0/templates/search']). at /usr/lib/perl5/site_perl/5.8.8/Tenjin/Engine.pm line 56.\n
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Apache 进程还需要对每个子目录直至完整路径的
读取和执行访问权限。 (如果涉及符号链接,则确定访问内容将更加棘手)。如果您可以在 Web 服务器上就地调试脚本,您可能希望 Perl 向您发送一条错误消息:
The Apache process also needs
read andexecute access on every subdirectory up to the full path. (If symbolic links are involved, it will be trickier to determine what the accesses are).If you can debug the script in place on the web server, you might want to get Perl to deliver you an error message:
-f 如果文件不存在则返回 false,但如果 stat 调用因其他原因失败则返回 undef。
测试返回是否已定义,如果未定义,则显示将在 $! 中设置的错误。
这可能会给你一个线索。
-f will return false if the file doesn't exist but undef if the stat call failed for some other reason.
Test if the return is defined and if it is not, show the error that will have been set in $!.
That may give you a clue.
为
-f
提供文件的完整路径,并确保 Apache 可以读取该文件。Give
-f
the full path to the file, and make sure it is readable by Apache.您使用的是绝对路径名还是相对路径名?您对当前目录的假设可能根本就是错误的。
Are you using absolute or relative pathnames? Your assumptions about the current directory may simply be wrong.
我将完全忽略您的问题并回答完全不同的问题!我就是这么疯狂!
好吧,不是真的,我正在利用核心 Perl 模块, File::Find ,而不是编写我自己的目录解析器。
根据要求,这是我实际回答的问题:
“如何找到位于一组特定路径的子目录中某个文件的路径?”
I'm going to totally ignore what you asked and answer something completely different instead! I'm just that crazy!
Well, not really, I'm leveraging a core perl module, File::Find, instead of writing my own directory parser.
On request, here's the question I'm actually answering:
"How do I find the path to a file that is somewhere in a sub-directory of a specific set of paths?"