【问题标题】:the file says it's there, but it's not really there at all文件说它在那里,但它根本不在那里
【发布时间】:2017-09-13 11:29:42
【问题描述】:

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

  1. 文件的目录存在
  2. -e 表示文件在那里
  3. 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 $cachepathopen my($in), '&lt;:raw', $cachepath 也可能会失败,因此除非$!No such file or directory,否则关于类似错误的全部内容是没有意义的。
  • 根据您的说法,同一进程中的unlinkopen 表示该文件不存在,而外部进程中的open (cat) 表示该文件不存在存在。如果它只是最后一个,我怀疑是一个可能无法打印的 shell 元字符。但是假设您只是间歇性地遇到此问题(对吗?),并且您自己的进程说该文件不存在,我相信该文件不存在。

标签: linux perl unix filesystems


【解决方案1】:

事实证明这确实是子进程和竞争条件。 Test::Simple 中较新的代码不适用于嵌套子测试。无论如何,感谢您允许我排除一些我不知道的晦涩的文件系统问题。

【讨论】:

    猜你喜欢
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2018-05-16
    • 2021-09-20
    相关资源
    最近更新 更多