【发布时间】:2016-10-17 19:54:12
【问题描述】:
我在我的应用程序中观察到非常奇怪的行为。
我有以下功能:
bool File::Exists(const std::string & Path)
{
struct stat S;
if(stat(Path.c_str(), &S) != 0)
return false;
if(!S_ISREG(S.st_mode))
return false;
return true;
}
void File::Remove(const std::string & Path)
{
if(unlink(Path.c_str()) != 0)
throw Exceptions::Exception(EXCEPTION_PARAMS, errno);
}
我使用的代码是:
...
const std::string Path = ...;
if(File::Exists(Path))
File::Remove(Path);
...
此时抛出异常:
No such file or directory (2)
关键事实:
- 每 1k-10k 调用发生一次
- 所有被删除的文件都是二进制文件,大约20MB
- 这是在应用程序线程中调用的,但是这是访问这些文件的唯一线程(没有其他线程/进程访问它们)。甚至没有他们所在的其他进程/用户访问分区。
- 要删除的文件位于已安装的 CIFS (SMB)(网络)安装点上
为什么 stat() 报告文件存在,但 unlink() 有时会失败?
【问题讨论】:
标签: c++ linux file filesystems