【发布时间】:2017-09-13 11:29:42
【问题描述】:
什么情况会导致这种情况?
- 文件的目录存在
- -e 表示文件在那里
- cat 说“没有这样的文件或目录”
opendir(my $dh, $tdir) or die "Could not open temp dir: $!";
for my $file (readdir($dh)) {
print STDERR "checking file $tdir/$file\n";
next unless -e "$tdir/$file";
print STDERR "here's the file for $tdir/$file: ";
print STDERR `cat $tdir/$file`;
die "Not all files from hub '$hid' have been collected!: $tdir/$file";
}
输出:
checking file
/tmp/test2~22363~0G0Tjv/22363~0~4~22380~0~1~Test2~Event~Note
here's the file for /tmp/test2~22363~0G0Tjv/22363~0~4~22380~0~1~Test2~Event~Note:
cat: /tmp/test2~22363~0G0Tjv/22363~0~4~22380~0~1~Test2~Event~Note: No such file or directory
IPC Fatal Error: Not all files from hub '22363~0~4' have been collected!:
我意识到理论上一些其他进程或线程可能会在周期之间踩到我的文件,但这是 Perl(单线程)和 Test2/Test::Simple 的测试目录,应该限制为由主进程。
让我来到这里的是,我在我们拥有的其他代码中看到了类似的错误:
if(-e $cachepath) {
unlink $cachepath
or Carp::carp("cannot unlink...
抛出“无法取消链接...”
还有
$cache_mtime = (stat($cachepath))[_ST_MTIME];
....
if ($cache_mtime){
open my($in), '<:raw', $cachepath
or $self->_error("LoadError: Cannot open $cachepath for reading:
抛出“LoadError:无法打开...”异常
这些情况也应该只有一个进程在目录上运行,这一切都让我怀疑发生了什么事。
这是 linux 内核,完全是最新的供应商补丁。
【问题讨论】:
-
它可能是一个损坏的符号链接吗?
-
你在 shell 中看到了什么?
ls -l?stat? -
@that other guy,猜对了,除了
-e返回错误的符号链接。 -
请注意,即使文件存在,
unlink $cachepath和open my($in), '<:raw', $cachepath也可能会失败,因此除非$!是No such file or directory,否则关于类似错误的全部内容是没有意义的。 -
根据您的说法,同一进程中的
unlink和open表示该文件不存在,而外部进程中的open(cat) 表示该文件不存在存在。如果它只是最后一个,我怀疑是一个可能无法打印的 shell 元字符。但是假设您只是间歇性地遇到此问题(对吗?),并且您自己的进程说该文件不存在,我相信该文件不存在。
标签: linux perl unix filesystems