文件说它在那里,但它根本不在那里

the file says it's there, but it's not really there at all

什么情况会导致这种情况?

  1. 文件的目录存在
  2. -e 表示文件在那里
  3. 猫说 "No such file or directory"
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...

抛出 "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: cannot open..." 异常

在这些情况下,应该只有一个进程在目录上运行,这一切让我怀疑发生了什么事。

这是 linux 内核,完全是最新的供应商补丁。

事实证明,这确实是子进程和竞争条件。 Test::Simple 中较新的代码不适用于嵌套子测试。不管怎样,谢谢你让我排除了一些我不知道的晦涩的文件系统。